--
Amistad Hou
"Laura" <alee...@SPAMgmail.com> ??? news:ef066...@webx.raydaftYaTP
???...
First of all, thank you for your reading and help but I think that
the solution you gave don't work properly.
In fact, in my Simulink model I have used that block to concatenate
the vector to the matrix, so 'Concatenate' block is not my problem.
My problem is the following: I know how to concatenate a row vector
to a matrix if the matrix has the same dimensions in each simulation
step, but how can I concatenate a vector to a matrix if that matrix
is initially empty and in each simulation I add a new row?
I would like to do the following in Simulink:
matrix = [];
for( i=1:var )
vector = ......(calculate vector value)
matrix = [ matrix; vector ];
end
An example of execution of that code would be like this:
(initially)
matrix = [];
(first step)
vector = [1 1 1];
matrix = [1 1 1];
(second step)
vector = [2 2 2];
matrix = [1 1 1; 2 2 2];
(third step)
vector = [3 3 3];
matrix = [1 1 1; 2 2 2; 3 3 3];
(N step)
vector = [N N N];
matrix = [1 1 1; 2 2 2; 3 3 3; ... N N N];
I think that I need to save the matrix values at the end of each
simulation step (because I need them in the next step), but I don't
know really how to do it. I have tried with 'Data store memory' but
in the initialization of this block I need to know the final
dimension of my matrix, and each time I use 'Data Write Memory' block
I have to write a matrix of that dimension exactly, so I can't change
the dimension in each simulation step.
Has anybody any other suggestion for my code?
Thank you very much.
Laura
%%%%%
function [sys,x0,str,ts] = sfunRR(t,x,u,flag)
switch flag,
case 0,
[sys,x0,str,ts] = mdlInitializeSizes(t,x,u);
case 2,
sys=mdlUpdate(t,x,u);
case 3,
sys=mdlOutputs(t,x,u);
case 9,
sys=mdlTerminate(t,x,u);
otherwise
error(['Unhandled flag = ',num2str(flag)]);
end
function [sys,x0,str,ts] =mdlInitializeSizes(t,x,u)
sizes=simsizes;
sizes.NumContStates=0;
sizes.NumDiscStates=0;
sizes.NumOutputs=0;
sizes.NumInputs=1;
sizes.DirFeedthrough=0;
sizes.NumSampleTimes=1;
sys=simsizes(sizes);
x0=[];
str=[];
ts=[0.1 0]; % I update the values each 0.1 seconds of simulation
function sys=mdlUpdate(t,x,u)
assignin('base','matrix_ti') % this could be your code
sys=[];
function sys=mdlOutputs(t,x,u)
sys=[];
function sys=mdlTerminate(t,x,u)
sys=[];
%%%%
FYI, in my model the s-function block containing this function has an
input and no outputs (you could add matrix_t(i-1) as an output...),
and no parameters as well.
Hope this helps,
Frank
such approach avoid the uncertainty of output dimension assignment and make
the algorithm to work in simulink. moreover, some functional ports like
"enable" ,"reset", and other control signals may be added to accomplish
desired
algorithms.
"Laura" <ale...@QUITAESTO.gmail.com> ??? news:ef06...@webx.raydaftYaTP
???...
Thank you again!