Vector to Matrix Conversion

1 回表示 (過去 30 日間)
Johnaton McAdam
Johnaton McAdam 2016 年 9 月 11 日
編集済み: Stephen23 2016 年 9 月 11 日
Hi guys i was wonder if there is a way in matlab to convert matrix from vector using loop. For example I have a X and Y vector and lets say i want to store every 2 lines as its own Row in its Matrix. Is there a way i can do this? Below is my attempted code.
for i = 1:45
X(1,i) = x(i,:);
Y(1,i) = y(i,:);
U(1,i) = u(i,:);
V(1,i) = v(i,:);
for o = 46:90
X(2,o) = x(o,:);
Y(2,o) = y(o,:);
U(2,o) = u(o,:);
V(2,o) = v(o,:);
end
end
i have to do this for 2050 iterations and is there a more efficient way to do this?
  1 件のコメント
Guillaume
Guillaume 2016 年 9 月 11 日
There is probably a way to do what you want in just one line. The problem is that the code you've posted does not make sense (you're trying to store several elements inside just one element) so it's not clear what you want.
Show an example with numbers of input and desired output

サインインしてコメントする。

回答 (1 件)

Stephen23
Stephen23 2016 年 9 月 11 日
編集済み: Stephen23 2016 年 9 月 11 日
"is there a more efficient way to do this?"
Probably reshape does exactly what you want. Perhaps in conjunction with a transpose or two as well.

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by