Comparing data in a spreadsheet
조회 수: 1 (최근 30일)
이전 댓글 표시
I have data that I need to compare. I am not sure how to code this in Matlab. So for instance, I have columns, A, B, and C as below.
A B C
5 1 2
4 2 3
3 3 4
2 4 5
1 5 3
. . .
. . .
. . .
. . .
How do I count and list all the 5s in A and show what the 5s in A listed for their B and C answers? For instance, for all the 5s in A: there are seven 1s, three 2s, etc in column B. And there are four 1s, eight 2s, etc, in column C that have 5s in A. And also show the sum.
댓글 수: 0
답변 (1개)
Image Analyst
2020년 12월 9일
To find the numbers of each number in the first column of A, do this
counts = histogram(A(:, 1))
To find the rows with a particular number in the first column, do this:
mask = A(:, 1) == 2; % Find rows where first column is 2.
maskedA = A(mask, :); % Only those rows where first column = 2.
To count the count of each number in the other columns, do
countsB = histogram(maskedA(:, 2));
countsC = histogram(maskedA(:, 3));
If tthat doesn't work, give a full sample matrix, and your expected output.
참고 항목
카테고리
Help Center 및 File Exchange에서 Database Toolbox에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!