how to use reshape ?

5 ビュー (過去 30 日間)
pruth
pruth 2020 年 7 月 3 日
コメント済み: pruth 2020 年 7 月 6 日
I have a matrix with - 23043864x3 double.
i want to split this matrix in to 339 rows using reshape.
So it wil becaome - 339 x (something) double.
any help would be apriciated !
thank you
  2 件のコメント
KSSV
KSSV 2020 年 7 月 3 日
If a is your array..
b = reshape(a,339,[]) ;
this is what you want?
pruth
pruth 2020 年 7 月 6 日
yess. thank you !!! it works !
i tried this before but without using comma. that is why got the error.

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

採用された回答

Gifari Zulkarnaen
Gifari Zulkarnaen 2020 年 7 月 3 日
try this:
B = reshape(A,339,[]); % A is the original matrix, B is the reshaped matrix
  1 件のコメント
pruth
pruth 2020 年 7 月 6 日
worked !! thanks !

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

その他の回答 (2 件)

John D'Errico
John D'Errico 2020 年 7 月 3 日
編集済み: John D'Errico 2020 年 7 月 3 日
The good thing about reshape is IF you put in an empty argument, then it figures out how many columns you will need.
But first, reshape will fail here, if the number of elements in your array is not an integer mutiple of 339.
(23043864*3)/339
ans =
203928
So the desired reshape will not fail.
However, you need not compute the number of columns yourself.
B = reshape(A,339,[]);
So the use of empty brackets tells reshape to figure out how many columns would have been necessary.
Finally, this even works to turn the matrix into a 3-dimensional matrix.
A = rand(23043864,3);
B = reshape(A,339,[],3);
size(B)
ans =
339 67976 3
As you should see, I never needed to compute the number of columns. Let reshape do the thinking for you.
  1 件のコメント
pruth
pruth 2020 年 7 月 6 日
thank you for the information !! I appreciate !

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


Alan Stevens
Alan Stevens 2020 年 7 月 3 日
If A is your 23043864x3 matrix, then
B = reshape(A, 339, 203928);
should work. Of course, you could simply use A where I've put B above if you no longer need the original A.

カテゴリ

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