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

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

What is the best function to plot/view a 79 by 79 matrix in order to have a clear information from the matrix
You will need to explain your goals more. What one person finds "clear" is not what a different person finds clear.
Thank you @Walter Roberson. My goal is to have a view of the'dominant' features from the matrix. The matrix was derived from eigendecompostion of sound data. Snippets of similar patterns (when viewed on sonic visualiser) from data were taken. Now, I want to compare if we will have the same pattern using MATLAB from different snippets (though same shape from spectrogram view)
Given that description... I do not think it is possible to plot/view the 79 x 79 matrix in order to have clear information from the matrix.
I was thinking what if I take the mean of the matrix (since this works column wise) in order to have a vector output. Then plot it, I don't know if this makes sense. If yes, back to my question: What will be the best plot function to use?
I am newbie, I hope my question doesn'tsound to elementary
The problem is not finding some way to plot the matrix. The problem is finding a way to plot to have clear information. It seems to me that the kind of information you are working with does not have a clear interpretation.
Consider for example if you take
x = rand(72,1);
x1 = sort(x);
plot([x,x1])
legend({'x', 'x1'})
x and x1 have the same mean, but it is highly likely that the interpretation of x and x1 should be very different.
But now for example,
x2 = reshape(reshape(x, 2, []).',[],1);
plot([x,x2])
Nearly the same but every pair has been exchanged, but if this was your measured features, then what would be the implication of this compared to the other one?
Or if the first entry of x1 (the sorted one) were decreased by 0.05 and the last five entries were increased by 0.01 each, the sort order would remain the same, and the mean would stay the same, but what would it mean ???
When you have 72 values, then what is the significance of the 11'th or 48'th being different ?
You can plot, yes, but humans are often pretty bad at immediately being able to figure out from a graph what it means for individual components to be particular values. So I do doubt that you can plot in a way that gives you clear information.
@Walter Roberson, thank you for the explanation. This is truly appreciated.

Sign in to comment.

 Accepted Answer

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)

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

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.

What is the original matrix you want to reshape? Is it signal?
If so, how about
reshaped = signal(1:fl, :)

Products

Release

R2021a

Asked:

on 5 Jul 2021

Commented:

on 7 Jul 2021

Community Treasure Hunt

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

Start Hunting!