Why variable has only 1 value after completing a cycle?

조회 수: 3 (최근 30일)
Naryna a
Naryna a 2022년 2월 5일
답변: Davide Masiello 2022년 2월 5일
I have an array A with float numbers and a fixed calculated number M. I`ve tried to write a cycle which would give me every nth element of an array if every (n+1)th element is less than my number M. Here is my code:
for l=find(A);
if l < length(A);
if A(l+1) < M;
X=A(l)
end;
end;
end;
After completing the cycle my variable X has only the first number of all that numbers that it should have. I think that it`s happenning because Matlab stops after finding first sufficient value, but I need it to work through all array. How can I change this code? Thank you for helping)

답변 (1개)

Davide Masiello
Davide Masiello 2022년 2월 5일
You need to index X too.
X(l)
Otherwise the values do not get stored in X, and you see only the last computed value.

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by