Borrar filtros
Borrar filtros

Error using reshape To RESHAPE the number of elements must not change.

1 visualización (últimos 30 días)
Hi everyone
cananyone help me please with the following error.
I'm getting the error "Error using reshape To RESHAPE the number of elements must not change."
windows=1;
wwf6=zeros(winsize,round(length(cleanAudio)/winsize));
pos=zeros(round(length(cleanAudio)/winsize));
for b=1:round(length(cleanAudio)/winsize)
pos(1)=1;
data1 = sig(pos(b): pos(b)+winsize-1).*(hamwin);
wwf6(:,b) = fft(data1);
windows = windows + 1;
pos(b+1) = pos(b) + winsize;
end
wwf6;
Y = reshape(wwf6,[length(cleanAudio),1]);
  2 comentarios
Mehmed Saad
Mehmed Saad el 13 de Abr. de 2020
because you are using round, size may differ due to roundoff
Roro
Roro el 13 de Abr. de 2020
even with changing round the issue still same, do you hav an y suggestion please?

Iniciar sesión para comentar.

Respuesta aceptada

KALYAN ACHARJYA
KALYAN ACHARJYA el 13 de Abr. de 2020
Editada: KALYAN ACHARJYA el 13 de Abr. de 2020
Must be same, see
Total Elements on wwf6=length(cleanAudio)*1
See the following example
>> A=magic(4)
A =
16 2 3 13
5 11 10 8
9 7 6 12
4 14 15 1
Total Elements in A=16, if you trying to reshape A with following, it reflects the same error, because [5,1] having 5 elements only
>> reshape(A,[5,1])
Error using reshape
To RESHAPE the number of elements must not change.
But following have no issue, as [8,2]=16 elemnets equalt to original A
>> reshape(A,[8,2])
ans =
16 3
5 10
9 6
4 15
2 13
11 8
7 12
14 1
Hope it Helps!

Más respuestas (2)

Ameer Hamza
Ameer Hamza el 13 de Abr. de 2020
Without the actual dataset, it is difficult to predict what is going on here, but I speculate that because you used round when initializing wwf6, in the end, the vector wwf6 is not of correct shape that can be reshaped. You can truncate the last few elements like this
Y = reshape(wwf6(1:floor(numel(wwf6)/numel(cleanAudio))*numel(cleanAudio)), [numel(cleanAudio),1]);

Mehmed Saad
Mehmed Saad el 14 de Abr. de 2020
suppose that
winsize = 85;
cleanAudio = rand(1,25000);
Now type following in cmd
(length(cleanAudio)/winsize)
= 25000/85
= 294.1176
Round it
294
Now multiply it back with winsize, the elements will be
294*85 = 24990
So you can see that you are 10 samples short due to rounding off bcz
wwf6=zeros(winsize,round(length(cleanAudio)/winsize));
Check the size of wwf6
size(wwf6)
= 85 294
In order to reshape it properly, do following
Y = reshape(wwf6,[winsize*round(length(cleanAudio)/winsize),1]);
But now your matrix size will be less than clearAudio
Truncate the cleanAudio to compare it with Y

Categorías

Más información sobre Line Plots en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by