How to convert variables with uncertain dimension size into C++ in m function
1 view (last 30 days)
Show older comments
In the m function in simulink, if the dimension of a variable is judged by the while statement, if while is true, the dimension of the variable will always increase. The dimension of this variable may not be large, or it may be particularly large. How to Write code without giving the maximum dimension of this variable in advance, and then convert it to C++ code (this variable is not an input and output variable, but a local variable in the function), there is example as follows: I don't konw the dimension size of F. The dimension size depondence on the 'while statement'.
function A = varytest(B)
C = rand(5);
D = ones(5,5);
E = D-C;
count = 1;
coder.varsize('F');
F = ones(1,5);
while (sum(E,'all')<20)
F(count,:) = count*ones(1,5);
count = count+1;
C = rand(5);
E = D-C;
end
G = F(end,:);
A = G+B;
end
%% the error as follows
% Error using varytest (line 9)
% Index exceeds array dimensions. Index value 2 exceeds valid range [1-1] for array 'F'.
0 Comments
Answers (0)
See Also
Categories
Find more on Uncertain Models in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!