How to obtain a fixed-size array from a variable-size array
Show older comments
I'm using the Matlab Function block in Simulink and I have the following problem :
In my code, I have a two vectors : 'A0', of fixed-size and 'A1', of variable-size.
The size of 'A0' is 'n0', thus A0(n0,1) The maximum size of A1 is 'n0'. Thus, (Size of A1) <= (Size of A0).
One of the outputs of my Matlab Function is A = A0 + A1. Since it's a sum of vectors, they must have the same size, so what I did is fill 'A1' with zeros until reaching the same size. For exemple :
n0 = length(A0);
n1 = length(A1) ;
m = n0 - n1 ;
if n1 < n0
A1_1 = [A1 ; zeros(m,1)] ;
else
A1_1 = A1 ;
end
A = A0 + A1_1 ;
I believe that with this code, 'A', 'A1_1' and 'A0' will always have the same fixed size (since the reference, 'A0', is already fixed). In my simulation, I get the value of 'A' that I desire.
The problem is that for Simulink, 'A' is still a variable-size array, so I can't branch its signal directly with some other blocks.
What I need is 'A' (or even 'A1_1') to be read by Matlab-Simulink as a fixed-size array.
Accepted Answer
More Answers (0)
Categories
Find more on Performance and Memory 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!