Sorting matrix through multiple conditions

Say i have a 12*2 matrix having two parameters where
a=[2;4;5;80;40;5;43;22;6;56;6;57] &
b=[100;122;132;120;108;200;231;211;165;127;130;150];
i want to get a column matrix using if else statement of 4 conditions like below.
the conditions are 1. 2<a<10 and 110<b<130
2. 40<a<50 and 220<b<250
the result will be like below, where the 1st condition match it will show 5, where the 2nd condition matches it will show 9 else it will show 0
final result=[0;5;0;0;0;0;9;0;0;0;0;0]

1 comentario

Jan
Jan el 29 de En. de 2019
Fine. What is your question? What have you tried so far and which problem occurs?
By the way, remember, that Matlab needs 2<a & a<10 and 2<a<10 is something different.

Iniciar sesión para comentar.

 Respuesta aceptada

Jan
Jan el 29 de En. de 2019
Editada: Jan el 29 de En. de 2019
Although I do not know, what the question is, a dare to guess:
a = [2;4;5;80;40;5;43;22;6;56;6;57];
b = [100;122;132;120;108;200;231;211;165;127;130;150];
c = zeros(size(a));
c( 2<a & a<10 & 110<b & b<130) = 5;
c(40<a & a<50 & 220<b & b<250) = 9;
You see: you have been almost there. I only replaced the logical expression "a<b<c" by a<b & b<c and the "and" by an "&".

Más respuestas (0)

Categorías

Preguntada:

el 29 de En. de 2019

Editada:

Jan
el 29 de En. de 2019

Community Treasure Hunt

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

Start Hunting!

Translated by