Creating subsets from a matrix and averaging them separately
Show older comments
I have a 43,692x1 matrix that I need to divide into subsets of 6x1 every 6 rows (i.e. a total of 7,282 subsets). In other words, I need to divide the original matrix every 6 rows. Then, I need to take the average of the three smallest values from each subset. Finally, I would need to average all the resulting values from the last operation to obtain a single value at the end. What would you suggest is the best approach for this challenge?
Answers (1)
Image Analyst
on 18 Nov 2015
Sounds like homework, so I'll just give you the steps: reshape into 6 columns, sort the rows horizontally, extract the left most 3 columns to get the smallest 3 numbers in each row. Take the mean:
reshapedData = reshape(data, [......]);
sortedData = sort(reshapedData, ......., '.....');
result = mean(sortedData(:,3), 2);
See if you can finish it - you're a smart engineer so I think you can do it.
2 Comments
Richard Joisce
on 28 Feb 2022
"See if you can finish it - you're a smart engineer so I think you can do it"
AKA "I cba to work it out properly".
An indredibly unhelpful response for future readers smh
Image Analyst
on 28 Feb 2022
Perhaps this reply would have offered additional help.
Note, we can't do the whole thing for them if it's homework but we can give them hints and encourage them to finish it themselves.
Categories
Find more on Get Started with MATLAB in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!