reshapeについてのエラーに関して

13 visualizaciones (últimos 30 días)
大樹 林
大樹 林 el 2 de Nov. de 2020
Respondida: michio el 4 de Nov. de 2020
ZN=482;
DOD=csvread('RDOD.csv');
DOD=permute(reshape(DOD,[ZN ZN 3]),[2 1 3]);
この際にエラーが生じて「要素数をRESHAPEするためにへんこうしてはいけません。」と表示され、解決できませんでした。この原因を教えてほしいです。

Respuestas (1)

michio
michio el 4 de Nov. de 2020
reshape は行列の形を変える関数ですので、変更前と変更後で要素の合計数が変わってしまう変更はできません。
例えば 1x10 のベクトルを 2x5 の行列に変更します。
x = 1:10;
reshape(x,2,5)
ans =
1 3 5 7 9
2 4 6 8 10
これは要素数がともに10で同じなので問題ないですが、例えば
reshape(x,1,5)
は x を 1x5 の行列に変更しようとしていますが、要素数が異なるのでエラーとなります。
reshape(DOD,[ZN ZN 3])
でエラーが出ているという事は、DOD という変数の要素数が ZNxZNx3 ではないことを意味しています。

Categorías

Más información sobre Statistics and Machine Learning Toolbox en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2015b

Community Treasure Hunt

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

Start Hunting!