Filter löschen
Filter löschen

How to count the number of "" true "" and ""false"" in matrix

169 Ansichten (letzte 30 Tage)
PRED LIU
PRED LIU am 25 Mai 2020
Beantwortet: Tommy am 26 Mai 2020
matrix AAA is
AAA = [...
true true false true true
true true true false false
true false false true true
]
How to know
the number of ""true"" is 10 pcs
the number of ""false"" is 5 pcs
How to show a message "True is 66.7%"

Akzeptierte Antwort

William Alberg
William Alberg am 25 Mai 2020
You can do something like this:
a = [
true true false true true
true true true false false
true false false true true
]
TRUES = sum(a,'all')
FALSES = size(a,1)*size(a,2) - TRUES

Weitere Antworten (1)

Tommy
Tommy am 26 Mai 2020
How to show a message "True is 66.7%"
fprintf('True is %.1f%%\n', 100*TRUES/numel(a));

Kategorien

Mehr zu Structures finden Sie in Help Center und File Exchange

Tags

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by