1行8列の行列を4行​2列の行列にするには​どうすればよいでしょ​うか。

6 Ansichten (letzte 30 Tage)
raonich
raonich am 18 Sep. 2021
Beantwortet: Hernia Baby am 18 Sep. 2021
matlabで[1,2,3,4,5,6,7,8] の行列を [1,2; 3,4; 5,6; 7,8]のように4行2列にするにはどうすればよいでしょうか。
  2 Kommentare
TT
TT am 18 Sep. 2021
x=1:8;
reshape(x,2,4)'
ans = 4×2
1 2 3 4 5 6 7 8
raonich
raonich am 18 Sep. 2021
thank you!!

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Hernia Baby
Hernia Baby am 18 Sep. 2021
@TT さんが記述しているようにreshape 関数をお使いください
x = 1:8
x = 1×8
1 2 3 4 5 6 7 8
ここで注意すべきは普通に4行2列にするとうまくいきません
reshape(x,4,[])
ans = 4×2
1 5 2 6 3 7 4 8
なので一度2行4列にして、転置することで実現できます
x = reshape(x,2,[])
x = 2×4
1 3 5 7 2 4 6 8
x = x.'
x = 4×2
1 2 3 4 5 6 7 8

Weitere Antworten (0)

Kategorien

Mehr zu Statistics and Machine Learning Toolbox finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!