How can i reshape a matrix to my preferred dimension and discard the excess element

13 views (last 30 days)
Cutie
Cutie on 5 Jul 2021
Commented: Cutie on 7 Jul 2021
I have a signal whose size is 48640 but I want to reshape it using window size 512,1024,..etc but the
[signal,Fs] = audioread('moan1_@24.36sec.wav');
fl = 512 % window size
X_data2 = reshape (signal, fl, []) % i want a matrix whose row is equal to window size fl
  7 Comments

Sign in to comment.

Accepted Answer

Walter Roberson
Walter Roberson on 5 Jul 2021
X_data2 = buffer(signal(:,1), fl)
This will create columns from the first channel of signal, with each column being fl samples long. As many columns will be needed as necessary. If the signal is not an exact multiple of fl then the last column will be 0 padded.
This requires the Communications Systems Toolbox.
It is one of the utility functions that I think really should be moved to basic MATLAB.

More Answers (2)

Srijan Jain
Srijan Jain on 5 Jul 2021
Hey
I understand that you are trying to remove the excess elements of a matrix. You may want to try:
childarray=parentarray(startrow:endrow, startcol:endcol);
Hope this helps
Srijan
  1 Comment
Cutie
Cutie on 6 Jul 2021
Can please explain further. When I tried it, the row work okay but the column is giving error as follows:
childarray=signal2(1:fl, 1:3); % but with error index in postition 2 excees array bounds (must not exceed 1). When I make the col side 1:1, I has as 8192 x 1 matrix

Sign in to comment.


Products


Release

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by