How to create another vector based on some if condition?

조회 수: 14 (최근 30일)
Elian Ricardo Gonzalez Beltran
Elian Ricardo Gonzalez Beltran 2019년 11월 26일
편집: Guillaume 2019년 11월 26일
I have a 2*1 vector of values
A = [500
200]
condition between or equal to 300 and 500.
Output should be.
B = [true
false];
Any simplest way without using loop. Any help is appreciated. Thanks

채택된 답변

Guillaume
Guillaume 2019년 11월 26일
편집: Guillaume 2019년 11월 26일
It's rare to have to use if in matlab, and it's certainly not the route to go if you want to operate on whole vectors or matrices at once since if only work with scalar expression. If you were to use if, you'd have to loop over your array.
Your A is trivially transformed into B with:
B = A >= 300 & A <= 500
No if or loop needed.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Multidimensional Arrays에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by