To RESHAPE number of elements must not change
7 次查看(过去 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!