" for element in List" - (simple problem)

Hi everyone,
i am new to programming but i know that you can write in Python something like this:
x3 = [5, 4, -3, -2]
j = 4
for element in x3:
if element > 0:
j =+ 1
print (j)
How to write those bold lines in Matlab?
I searched in google but could't find anything.
Thanks a lot!

 채택된 답변

Mathieu NOE
Mathieu NOE 2020년 11월 13일

1 개 추천

hello Mike
this is it
please check if the display of j is in the inner our the outer loop
x3 = [5, 4, -3, -2]
j = 4
for ci = 1:length(x3)
if x3(ci) > 0
j = j +1;
disp(j)
end
end

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Call Python from MATLAB에 대해 자세히 알아보기

질문:

2020년 11월 11일

답변:

2020년 11월 13일

Community Treasure Hunt

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

Start Hunting!

Translated by