Clear Filters
Clear Filters

How to make matrix?

1 view (last 30 days)
Saka Toshi
Saka Toshi on 4 Sep 2016
Answered: Star Strider on 4 Sep 2016
How to make a matrix? This matrix A is made by vectors. Now, A is 3-dimension, A=[Y3,Y2,Y1]
These matrix are made by data vectors y.
Y3=y(3:end);Y2=y(2:end-1);Y1=y(1:end-2);
How to make this matrix A which has any dimensions????

Answers (2)

Stephen23
Stephen23 on 4 Sep 2016
Edited: Stephen23 on 4 Sep 2016
How to create matrices and arrays is explained in the MATLAB documentation:
In your code you might like to experiment with cat to create a 3D array:
cat(3,y(3:end),y(2:end-1),y(1:end-2))
You could also use reshape, but keep in mind that MATLAB works along columns and then rows.
(learning to avoid numbered variables is a good idea too).

Star Strider
Star Strider on 4 Sep 2016
If you’re interested in the minimum value of the length of the vector ‘y’ that will satisfy all these vectors, a little recreational algebra (substituting ‘L’ for end, the last element in the vector) gives:
L-2 - 1 = y
L-1 - 2 = y
L - 3 = y
———————————————
3*L-3 - 6 = y
3*(L-1) - 6 = y
(L-1) - 2 = y
———————————————
L - 3 = y
Add 1 because of the addressing conventions, and the minimum vector length ‘y’ = 4. Trivial, and possibly completely irrelevant, but fun!

Categories

Find more on Matrices and Arrays in Help Center and File Exchange

Tags

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!