To RESHAPE number of elements must not change
30 views (last 30 days)
Show older comments
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 Comments
Answers (3)
John D'Errico
on 16 Aug 2024 at 19:18
Edited: John D'Errico
on 16 Aug 2024 at 19:28
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 Comments
Star Strider
on 16 Aug 2024 at 19:29
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 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!