To RESHAPE number of elements must not change
30 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Sahana
el 16 de Ag. de 2024 a las 19:14
Respondida: Star Strider
el 16 de Ag. de 2024 a las 19:29
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 comentarios
Respuestas (3)
John D'Errico
el 16 de Ag. de 2024 a las 19:18
Editada: John D'Errico
el 16 de Ag. de 2024 a las 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 comentarios
Star Strider
el 16 de Ag. de 2024 a las 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 comentarios
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!