How to make matrix?

3 ビュー (過去 30 日間)
Saka Toshi
Saka Toshi 2016 年 9 月 4 日
回答済み: Star Strider 2016 年 9 月 4 日
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????

回答 (2 件)

Stephen23
Stephen23 2016 年 9 月 4 日
編集済み: Stephen23 2016 年 9 月 4 日
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 2016 年 9 月 4 日
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!

カテゴリ

Help Center および File ExchangeMatrices and Arrays についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by