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]);

采纳的回答

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