If and & conditions together

조회 수: 1 (최근 30일)
Angelavtc
Angelavtc 2020년 11월 5일
답변: Walter Roberson 2020년 11월 5일
How can I properly formulate the following if.
I want to compare each element of 2 vectors [x1_grid and x2_grid] with the same size (1x671) .
If x1_grid(1) < x2_grid(1) & x1_grid(2) < x2_grid(2) & .... x1_grid(end) < x2_grid(end)
Then I want to write a vector [x1_is_less =1] but if only one of the and's is not holding then I want to write [x1_is_less =0]
This is my code, but something is not really working as I want, I guess my problem is to introduce the "and" condition within the loop.
can someone help me?
Thanks in advance!
for i = 1 : length(x1_grid)
if x1_grid(i) < x2_grid(i)
x1_is_less = 1;
else
x1_is_less = 0;
end
end

채택된 답변

Walter Roberson
Walter Roberson 2020년 11월 5일
x1_is_less = all(x1_grd < x2_grid);

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Dates and Time에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by