I'm trying to generate C-Code from a MATLAB function. I have to work with cell arrays (I cannot change this) and there are occurring two problems:
1: I want to truncate a cell array, i.e.
arr = cell(1,n);
% ...
arr = arr(1:m); % with m<n
MATLAB Coder forbids the (...) indexing, so I tried the following
tmp = arr;
arr = cell(1,m);
for i = 1:m
arr{i} = tmp{i};
end
But this will throw the error, that 'Matlab is unable to determine that every element of tmp{:} is assigned before this line'. The same happens if I assign every element of arr to tmp in a loop.
Do you know how to fix this, so that MATLAB Coder won't throw any errors.
Depending on what version of MATLAB Coder you're using you can get this error. In order to avoid the complete assignment detection problem you can type:
arr = coder.nullcopy(cell(1,m));
But you need to promise you're writing to every cell element after that assignment (which you are doing, because
for i = 1:m
arr{i} = tmp{i};
end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With