Shrinking a Sparse Matrix

3 views (last 30 days)
Manjot Singh
Manjot Singh on 29 Nov 2015
Edited: Manjot Singh on 13 Dec 2015
I have a sparse matrix and I want to kind of shrink its size by storing just one column per every 10 columns in the matrix. Is there a way to do this?
  2 Comments
Steven Lord
Steven Lord on 29 Nov 2015
Please give a small example of how you want to collapse 10 columns down into 1. Do you want to add the columns together, take the average, take just the first of each group of ten, or something more complicated?
Manjot Singh
Manjot Singh on 29 Nov 2015
Edited: Manjot Singh on 13 Dec 2015
I just wanted to take the first out of each 10 columns, as Walter Roberson has mentioned below. But now you have mentioned that, can you tell me how we can take average of these columns?

Sign in to comment.

Accepted Answer

Walter Roberson
Walter Roberson on 29 Nov 2015
NewMatrix = YourMatrix(:,1:10:end);
  2 Comments
Manjot Singh
Manjot Singh on 29 Nov 2015
This was what I was looking for. Thank you.
Walter Roberson
Walter Roberson on 29 Nov 2015
To take the mean:
(YourMatrix(:,1:10:end) + YourMatrix(:,2:10:end) + YourMatrix(:,3:10:end) .... YourMatrix(:,10:10:end))/10
You might want to use a loop:
NewMatrix = YourMatrix(:,1:10:end);
for K = 2 : 10
NewMatrix = NewMatrix(:,K:10:end);
end
NewMatrix = NewMatrix / 10;

Sign in to comment.

More Answers (0)

Categories

Find more on Sparse Matrices in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!