If statement for the structure in table
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
NA
am 12 Okt. 2020
Bearbeitet: madhan ravi
am 12 Okt. 2020
I have a table like this:
%% table info
alphabet = {'A';'A';'B';'A';'C';'D';'C'};
val = [52.1;20.0;13.27;10.49;4.35;4.16;3.78];
relation = {[2,5];[2,5];3;[10,11];2;5;9};
inx = [2;2;5;6;10;12;12];
T = table(alphabet,val,relation,inx);
I have two problems. First, want to find the rows that consist of 'A'.
find(T.alphabet{:}=='A')
Second, count the occurrences of 'A', 'B', 'C', and 'D'.
I try to use 'accumarray' but it does not work.
0 Kommentare
Akzeptierte Antwort
madhan ravi
am 12 Okt. 2020
Bearbeitet: madhan ravi
am 12 Okt. 2020
FIND_rows_of_A = find(strcmp(T.alphabet, 'A'))
%or
FIND_rows_of_A = find(ismember(T.alphabet, 'A'))
[Alphabets, ~, c] = unique(T.alphabet);
counts = accumarray(c, 1); % use it the right way ;)
Wanted = [array2table(Alphabets), array2table(counts)]
% if you're using recent versions of MATLAB then
Wanted = groupsummary(T, 'alphabet')
%or
Wanted = groupcounts(T, 'alphabet')
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Tables finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!