Containg the especific number in the vector
조회 수: 1 (최근 30일)
이전 댓글 표시
Guilherme Lopes de Campos
2019년 2월 7일
댓글: Guilherme Lopes de Campos
2019년 2월 7일
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
채택된 답변
madhan ravi
2019년 2월 7일
No loops needed:
numbers_greater_than_one_or_equal = nnz(b>=1)
numbers_lesser_than_one = nnz(b<1)
댓글 수: 3
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Startup and Shutdown에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!