MATLAB: Values of vectors in matrix (changes in time)

matrixvector

Hello guys, how may I do this..
I have 4 vectors (signals in time)
t =0:pi/20:4*pi;
x1 = cos(t);
x2 = cos(2*t);
x3 = cos(3*t);
x4 = cos(4*t);
And I want to put current value of signal to matrix:
x = [x1 x3]
[x2 x4]
But for t = 0 values of signals in t = 0; for t = t0 + t_step … etc, Just changes values in matrix in time, I hope you understard 🙂
Any idea?

Best Answer

Since all the x variables are functions of the same t variable you should be able to create a matrix by:
for m = 1:length(t)
x(m,:,:) = [x1(m) x2(m);x3(m) x4(m)];
end
This should create a multidimensional array with the first dimension having the same length as t and the two other dimension having a length of 2.
x(10,:,:)
will access the 2x2 matrix for t = t0+9*t_step.
Related Question