Error using reshape To RESHAPE the number of elements must not change.
1 view (last 30 days)
Show older comments
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 Comments
Accepted Answer
KALYAN ACHARJYA
on 13 Apr 2020
Edited: KALYAN ACHARJYA
on 13 Apr 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!
0 Comments
More Answers (2)
Ameer Hamza
on 13 Apr 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]);
0 Comments
Mehmed Saad
on 14 Apr 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
0 Comments
See Also
Categories
Find more on Resizing and Reshaping Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!