Problem with making a matrix of size [2 2 4 2] , need help

1 回表示 (過去 30 日間)
Nasir Qazi
Nasir Qazi 2014 年 5 月 22 日
コメント済み: John D'Errico 2014 年 5 月 22 日
if true
% I want to make a matrix of this size( 2 2 4 2) from this following data set
Data = [12.2537 13.4153
10.3552 12.3899
9.5644 12.1267
0.8660 0.5590
4.4718 5.1405
4.1300 3.7492
4.0248 3.0958
0.5590 0.5000
6.9277 6.9114
6.2339 6.2827
6.0672 6.1021
0.3535 0.4146
13.8229 5.1168
12.5654 4.3318
12.2043 4.1110
0.4146 0.4330]
for i=1:2
for j=1:2
for k=1:4
for m=1:2
A_int(i,j,k,m) = Data(i,j,k,m)
end
end
end
end
and I want to allocate this to A_int, I have tried something like that but it doesn't work Can somebody help me in this please Regards, end

採用された回答

John D'Errico
John D'Errico 2014 年 5 月 22 日
It is time to learn how to use reshape.
help reshape
As importantly, you need to understand that you cannot index an 8x2 array with four indexes as you have tried. MATLAB cannot read your mind.
  2 件のコメント
Nasir Qazi
Nasir Qazi 2014 年 5 月 22 日
brilliant thanks alot , even I know I am doing it wrong but i couldn't able to figure it out how can I make a matrix of [2 2 4 2] out of 16 x 2 array.
John D'Errico
John D'Errico 2014 年 5 月 22 日
Never copy numbers like this with loops.
reshape(A,[2 2 4 2])
If the numbers are not in the order you wanted, then learn to use permute.

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

その他の回答 (2 件)

Harshvardhan
Harshvardhan 2014 年 5 月 22 日
reshape(Data, [2 2 4 2])
Does that do that job for you?
  1 件のコメント
Nasir Qazi
Nasir Qazi 2014 年 5 月 22 日
yes that does it all cheers for that bud

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


Yao Li
Yao Li 2014 年 5 月 22 日
Data is a 16 x 2 matrix, so Data(i,j,k,m) is wrong.

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by