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

조회 수: 1 (최근 30일)
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
Mehmed Saad
Mehmed Saad 2020년 4월 13일
because you are using round, size may differ due to roundoff
Roro
Roro 2020년 4월 13일
even with changing round the issue still same, do you hav an y suggestion please?

댓글을 달려면 로그인하십시오.

채택된 답변

KALYAN ACHARJYA
KALYAN ACHARJYA 2020년 4월 13일
편집: KALYAN ACHARJYA 2020년 4월 13일
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!

추가 답변 (2개)

Ameer Hamza
Ameer Hamza 2020년 4월 13일
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 2020년 4월 14일
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

카테고리

Help CenterFile Exchange에서 Line Plots에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by