필터 지우기
필터 지우기

For and if loops

조회 수: 2 (최근 30일)
ii
ii 2019년 10월 28일
댓글: Star Strider 2019년 10월 29일
Quite an easy question I am trying to combine data from two rows, row 3 and row 6 when creating my loop.
for v=1:10
if RT(3,6,v)>0.9
v
end
end
Putting a comma shows a error message and if i use a colon it'll show me from row 3 to row 6 which I dont want. So how can I create this loop with two different rows? Thanks!!

채택된 답변

Star Strider
Star Strider 2019년 10월 28일
The immediate solution is to use square brackets:
RT([3,6],v)
There needs to be some delimiter between the ‘3’ and the ‘6’, a space will do as well.
The larger problem is the logical comparison. The comparison is between two vectors, so it is necessary to be explicit with respect to the result you want.
Example —
A = randi(10,2,10);
C1 = A < 5
C2a = all(A < 5, 1) % Compare Rows
C2b = all(A < 5, 2) % Compare Columns
C3a = any(A < 5, 1) % Compare Rows
C3b = any(A < 5, 2) % Compare Columns
Choose the appropriate syntax to get the result you want from your comparison.
  댓글 수: 2
ii
ii 2019년 10월 29일
Thank you!!
Star Strider
Star Strider 2019년 10월 29일
As always, my pleasure!

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

James Tursa
James Tursa 2019년 10월 28일
RT([3,6],v) is the syntax to use for the 3rd and 6th rows of the v'th column of RT. But this is of course going to be two elements, so I don't know what you intend the if-test to do with that. Do you want something to happen if both elements are greater than 0.9? If so, then
if( all( RT([3,6],v) > 0.9 ) )

카테고리

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