Comparing data in a spreadsheet

2 vues (au cours des 30 derniers jours)
Sunshine
Sunshine le 9 Déc 2020
Commenté : Sunshine le 9 Déc 2020
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.

Réponses (1)

Image Analyst
Image Analyst le 9 Déc 2020
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.
  1 commentaire
Sunshine
Sunshine le 9 Déc 2020
This does help. However, I was wondering about the following:
counts = histogram(A(:, 1))
This does give a histogram of the count in column 1. However, is there any way to list the output in a table? Like...
1s 47
2s 34
3s 23
The other commands do provide some input. However, this is what I am looking to do. In the attached example file, for every 1 in column A, I want to list out each of the values in Column B that have 1 in Column A. So for instance, A4, A5, A7, A9,... have 1s. I want to list and count each corresponding value in Column B. So something like the table in F - P in the spreadsheet. Because A4 has 1 and B4 has 7, and A7 has 1 and B7 has 7, in the table I count two 7s. Likewise, A5 has 1 and B5 has 3, so I count one 3 in the table.
Then finish the table with the 2s, 3s, 4s, and 5s from Column A, and give the count for the corresponding values in Column B.
Thanks for your help.

Connectez-vous pour commenter.

Catégories

En savoir plus sur AI for Signals dans Help Center et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by