필터 지우기
필터 지우기

How do I get a for loop to check a row for conditions?

조회 수: 5 (최근 30일)
William Grant
William Grant 2020년 4월 8일
댓글: William Grant 2020년 4월 8일
Hey Everyone: I'm going to try and phrase this as best I can, I'm quite new to matlab and coding but I need help with this vital skill.
I want to write a for loop that checks multiple conditions:
This is my Matrix I will analyse.
[170 284 60
292 380 69
294 397 82]
I want to check if element 1 is greater than some number, element 2 is greater than some number and element 3 is greater than some number. I also want it to check row by row and tell it to consider [170 284 60] as row 1, [292 380 69] as row 2 and [294 397 82] is row 3.
Can anyone help me out?

채택된 답변

Ilian
Ilian 2020년 4월 8일
If you want to use a for loop, you could have a look at if statement with multiple conditions
% Your conditions
a = 200;
b = 200;
c = 80;
A = [170 284 60; 292 380 69; 294 397 82];
for i = 1:3
if A(i,1) > a && A(i,2) > b && A(i,3) > c
disp(A(i,:)) % display rows that fulfill all conditions.
end
end

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by