How to count the number of cells from one column of an array variable table with a certain value?
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
regina
am 11 Okt. 2015
Kommentiert: Star Strider
am 11 Okt. 2015
I'm very new to matlab, I have a table with several columns and almost 10,000 rows, each column contains a different set of data. I need count the number of cells in column 2 that have the number 2 in them (the cells contain numbers 1-9).
So far I have
month=tab(tab(:,2)>1 & tab(:,2)<3 ,:);
res{2}=numel(month);
where res{2} is question number 2
the answer should be 2000, but it's coming in at 11900. Any help is greatly appreciated!
0 Kommentare
Akzeptierte Antwort
Star Strider
am 11 Okt. 2015
Your code:
month=tab(tab(:,2)>1 & tab(:,2)<3 ,:);
res{2}=numel(month);
is counting all the elements in the rows that meet the condition. See if:
res{2}=length(month);
or:
res{2}=size(month,1);
give you the result you want.
2 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Logical finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!