Shrinking a Sparse Matrix
3 views (last 30 days)
Show older comments
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
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?
Accepted Answer
Walter Roberson
on 29 Nov 2015
NewMatrix = YourMatrix(:,1:10:end);
2 Comments
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;
More Answers (0)
See Also
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!