Plotting mean of values based on number in column
이전 댓글 표시
I have a matrix [1,2,3,4,5,6; 1,2,1,2,1,2] I want to plot the mean of the values in row one based off of the values in row two i.e. the mean of 1,3,5 (because they correspond to the 1's in the second row) and the mean of 2,4,6 (because they correspond to the 2's in the second row).
The data I am actually working with is a 2X1000 matrix and has 5 different values in the second row but I want to use this example to simplify it so I can learn how to do it.
Maybe using an If loop? Or some other way of having Matlab go through the second row and store the contents of the first row into a separate matrix based off of some parameters?
I'm very new to Matlab, so the more detailed the explanation, the better.
Thank you!
채택된 답변
추가 답변 (1개)
Andrei Bobrov
2013년 7월 10일
편집: Andrei Bobrov
2013년 7월 10일
m = [1,2,3,4,5,6; 1,2,1,2,1,2];
means = accumarray(m(2,:).',m(1,:),[],@mean);
카테고리
도움말 센터 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!