Comparing data in a spreadsheet
2 次查看(过去 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 中查找有关 AI for Signals 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!