how to find correlation between two columns, selecting rows on the basis of third column
조회 수: 2 (최근 30일)
이전 댓글 표시
Hi
I have three column data say A, B and C and the number of rows be 1000. Column A is either empty or it has values from 1 to 3 randomly. B and C are two variables. Let's say values of B and C in each row is a case and value of A in the same row assigns the category to that case. So there are (1+3)four categories of cases in b and C. I need to find correlation between B and C with in each category.
Any idea how to do that?
댓글 수: 0
채택된 답변
David Young
2012년 3월 28일
I'm not sure what you mean by column A possibly being empty. Anyway, assuming that it contains the categories, you select the values in a particular category like this:
category = 2; % for example - could be any valid value
k = A == category; % find indexes of elements in this category
Bselected = B(k);
Cselected = C(k);
Now you can use your usual correlation function to find the correlation between Bselected and Cselected. You could put the whole lot in a loop to cover each category in turn.
댓글 수: 2
추가 답변 (1개)
Muhammad
2012년 3월 28일
댓글 수: 3
David Young
2012년 3월 28일
See above. Is A a cell array?
The code in my answer above gives you exactly what you are asking for, when the category has a number.
If this still doesn't help, perhaps you can show the code that assigns values to the variables A, B and C. (They are variables in MATLAB, aren't they?)
참고 항목
카테고리
Help Center 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!