To RESHAPE number of elements must not change
6 ビュー (過去 30 日間)
古いコメントを表示
Hi all, im trying to do simple ERP study using EEGLAB. To RESHAPE number of elements must not change, such an error messahe was thrown. let me know how to fix it. Thanks
0 件のコメント
回答 (3 件)
John D'Errico
2024 年 8 月 16 日
編集済み: John D'Errico
2024 年 8 月 16 日
How do you fix it? Make sure you know what the size of your array is, before doing a reshape. This way when you do that reshape operation, you won't be surprised.
Exactly what should MATLAB do for this case:
x = 1:5;
reshape(x,2,3)
that error message tells you that you are trying to stuff something into a container of the wrong size. In this example, if you try to turn 5 elements into 6 elements, MATLAB tells you there is a problem, and that problem is yours to resolve. All MATLAB can know is you did something wrong.
And don't tell me that MATLAB should just know to pad the array with zeros if necessary, or delete elements if too many are provided. There will be others who will equally vociferously shout that MATLAB should be smart enough to resample the data over a longer or shorter range as needed.
In general, the way to fix it is to just follow good coding practice. Know what you are working with. Know what you are doing to it.
0 件のコメント
Star Strider
2024 年 8 月 16 日
An alternative to reshape that you may want to use instead is the Signal Processing Toolbox buffer function. With a vector input, the output is a matrix. In order to make it work as a matrix, the unfilled elements in the last column of the output matrix are zero, so consider that.
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Resizing and Reshaping Matrices についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!