I have two matrices. One for example is A = 520 x 1 and it has numbers from 1-8 which are not in order. For every number in this matrix, I have corresponding 1000 samples in another matrix B 520 x 1000. I want to first sort A and arrange numbers from 1-8 for every 8 rows. So output should be (1,2,3,4,5,6,7,8,1,2,3,4,5 and so on) and arrange corresponding values in B also such that they match.
Once this is done, I want to average every 5 rows of B and store it in a new matrix which will be 104 x 1000.
I kind of dealt with the point 1. So i concatenated A and B and sorted rows according to numbers from 1-8. I am looking to see if there is a better method to do this and point 2 which is averaging every 5 rows.
Thank you @Matt J and @Guillaume for your inuputs.
I tried sorting using @Matt J's method but it did not sort the elements.
Also from the question, A and B actually have same number of rows so A will be 520 x 1. After sorting A & B there should be still 520 rows and then after taking mean result should be 104 x 1000. @Guillaume your method gives the result as 520 x 1000.
Thanks @Matt J. This seems to work and I am getting the correct size of the result matrix but the mean values of result are different from those I calculated manually for a few rows. Is this method calculating mean for rows 1-5,6-10,11-15 and so on? if you can comment the steps that might be helpful to debug.
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
4 Comments
Direct link to this comment
https://au.mathworks.com/matlabcentral/answers/479608-sorting-and-averaging-matrices#comment_744059
Direct link to this comment
https://au.mathworks.com/matlabcentral/answers/479608-sorting-and-averaging-matrices#comment_744059
Direct link to this comment
https://au.mathworks.com/matlabcentral/answers/479608-sorting-and-averaging-matrices#comment_744063
Direct link to this comment
https://au.mathworks.com/matlabcentral/answers/479608-sorting-and-averaging-matrices#comment_744063
Direct link to this comment
https://au.mathworks.com/matlabcentral/answers/479608-sorting-and-averaging-matrices#comment_744065
Direct link to this comment
https://au.mathworks.com/matlabcentral/answers/479608-sorting-and-averaging-matrices#comment_744065
Direct link to this comment
https://au.mathworks.com/matlabcentral/answers/479608-sorting-and-averaging-matrices#comment_744069
Direct link to this comment
https://au.mathworks.com/matlabcentral/answers/479608-sorting-and-averaging-matrices#comment_744069
Sign in to comment.