If statement with multiple condition

Hi,
I read few post and could not solve my issue with if statement. I have the following code but it doesn't work!
i=1;
for j = 1 : height (reduced)
if (Boarder_Lat_lower < reduced(j, 4)) && (reduced(j, 4) < Boarder_Lat_upper) && (Boarder_Long_lower < reduced (j, 5)) && (reduced (j, 5) < Boarder_Long_upper)
Selected_2011 (i, :) = reduced (j, :);
i= i+1 ;
end
end
The problem is with multiple conditions separated with "and".
Thank you for the help

댓글 수: 7

James Tursa
James Tursa 2016년 9월 22일
What is the specific problem? Why are you incrementing j inside the for loop that already has j as an index? Are you intentionally trying to get j to increment by 2 each iteration? Or ...?
Kaveh Kel
Kaveh Kel 2016년 9월 22일
편집: Walter Roberson 2016년 9월 22일
I editted the code, j should not be in the loop.
The problem is with this part:
(Boarder_Lat_lower < reduced(j, 4)) && (reduced(j, 4) < Boarder_Lat_upper) && (Boarder_Long_lower < reduced (j, 5)) && (reduced (j, 5) < Boarder_Long_upper)
there are 4 conditions that I want to have in the if statement.
Walter Roberson
Walter Roberson 2016년 9월 22일
Are you getting an error message, or is it just not behaving as you expect?
Kaveh Kel
Kaveh Kel 2016년 9월 22일
I'm getting error.
James Tursa
James Tursa 2016년 9월 22일
Can you please post the error message? Copy and paste the entire message.
Walter Roberson
Walter Roberson 2016년 9월 22일
The code would be in error if any of the Boarder_* variables are not scalars.
Kaveh Kel
Kaveh Kel 2016년 9월 22일
Yes, the problem was with "reduced" table -- I imported the excel file as a table.
In the code, I changed the (e.g.) "reduced(j, 4)" to "reduced.Latitude (j)" and it worked. but the problem that I still have is regard to text values, that I cannot recall from the table.
I used this code:
Selected_C (i, 3) = reduced.Name (j);
("name" is one of the column title of reduced table )
but it doesn't work
Thanks!

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

답변 (0개)

카테고리

도움말 센터File Exchange에서 Tables에 대해 자세히 알아보기

질문:

2016년 9월 22일

댓글:

2016년 9월 22일

Community Treasure Hunt

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

Start Hunting!

Translated by