Containg the especific number in the vector
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Guilherme Lopes de Campos
am 7 Feb. 2019
Kommentiert: Guilherme Lopes de Campos
am 7 Feb. 2019
Hi MATLAB Community,
I would to ask a help please,
my purpose in the follow code is counting, how many number greater 1 or equal (x>=1), and put in a variable the number of values greater 1.
The code are as follows:
Which is my mistake in the code?
Error message :
Invalid expression. Check for missing multiplication operator, missing or unbalanced delimiters, or other syntax error.
To construct matrices, use brackets instead of parentheses.
Thank you very much for attention
Guilherme Lopes
b = linspace(0,5,20);
n=0;
m=0;
for b = 1:n
if b(1,:n)>=0
n = n+1;
else
m=m+1;
end
end
2 Kommentare
Akzeptierte Antwort
madhan ravi
am 7 Feb. 2019
No loops needed:
numbers_greater_than_one_or_equal = nnz(b>=1)
numbers_lesser_than_one = nnz(b<1)
3 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Historical Contests 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!