Whats the difference between the two statements

1 回表示 (過去 30 日間)
Kaavya N
Kaavya N 2020 年 12 月 13 日
コメント済み: Walter Roberson 2020 年 12 月 13 日
Difference between
(reshape(key,2,[])')
and
reshape(key,2,[])

回答 (2 件)

Cris LaPierre
Cris LaPierre 2020 年 12 月 13 日
Explained here (with an example).
"Specify [] for the first dimension to let reshape automatically calculate the appropriate number of rows."
If you specify [] in the second dimention, it will automatically determine the appropriate number of columns for the specified number of rows.
  1 件のコメント
Cris LaPierre
Cris LaPierre 2020 年 12 月 13 日
Ah, missed the transpose (the apostrophe) after the first one. That transposes the results of reshape. It's probably just easiest to test it and see:
key = magic(4);
reshape(key,2,[])'
ans = 8×2
16 5 9 4 2 11 7 14 3 10 6 15 13 8 12 1
reshape(key,2,[])
ans = 2×8
16 9 2 7 3 6 13 12 5 4 11 14 10 15 8 1
Another way is to just swap the 2 and the [].
reshape(key,[],2)
ans = 8×2
16 3 5 10 9 6 4 15 2 13 11 8 7 12 14 1

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


Bruno Luong
Bruno Luong 2020 年 12 月 13 日
The second creates 2-row matrix.
The first creates 2-column matrix, since it make a transpose after reshape.
  1 件のコメント
Walter Roberson
Walter Roberson 2020 年 12 月 13 日
More specifically, a conjugate transpose.

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

カテゴリ

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