Error using reshape To RESHAPE the number of elements must not change.
1 view (last 30 days)
Show older comments
Please help me with this Matlab code error
fileTx = 'Plosives.wav';
[fData,Fs] = audioread(fileTx);
orig_size = size(fData);
binData = dec2bin(typecast(single(fData(:)),'uint8'),8);
txAudio = reshape((binData-'0').',1,[]).'; % Create binary stream
str = reshape(sprintf('%d',rxData(1:length(txAudio))),8,[]).';
decdata = uint8(bin2dec(str));
rxAudio = reshape(decdata,orig_size);
% Play received audio
sound (rxAudio,Fs);
4 Comments
dpb
on 23 Apr 2018
Edited: dpb
on 23 Apr 2018
Can't do anything without input; again set a breakpoint in the editor and step through the code and see where it breaks or use
dbstop if error
and then run the code and it will stop on the error at which point you can investigate.
You haven't even told us which of the several reshape lines threw the error; what are we supposed to do, purchase the Crystal Ball Toolbox?
Answers (1)
dpb
on 23 Apr 2018
Edited: dpb
on 23 Apr 2018
Well, if I just make up a .wav file and try your code on it I find
[fData,Fs] = audioread('handel.wav');
orig_size = size(fData);
binData = dec2bin(typecast(single(fData(:)),'uint8'),8);
txAudio = reshape((binData-'0').',1,[]).'; % Create binary stream
str = reshape(sprintf('%d',rxData(1:length(txAudio))),8,[]).';
decdata = uint8(bin2dec(str));
rxAudio = reshape(decdata,orig_size);
Undefined function or variable 'rxData'.
>>
In which the data argument for the reshape in
str = reshape(sprintf('%d',rxData(1:length(txAudio))),8,[]).';
isn't defined; ergo, I'm going to guess you have a variable rxData in your workspace that isn't of the same size as was the input file you read and that's the problem.
Add
clear
to your script file and I'll bet the symptoms change.
However, don't think that will likely solve your problem entirely as when you get through with the line
binData = dec2bin(typecast(single(fData(:)),'uint8'),8);
the size of binData is going to be 32x that of fData
I've really no idea what any of the above is really intended to do but it's got some serious issues...
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!