MATLAB: Data of two column matrix .(A&B) extract corresponding elements from B ,according to some conditions in A.and add that elements and give a single element according to the conditions

for loopif statement

sample data
A= [1 5 10 5 2 12]
B= [10 30 30 40 50 60 ]
conditions
A<4
4<A<9
A>9
expected result
A<4 =60
4<A<9 =70
A>9 =90
help me

Best Answer

A= [1 5 10 5 2 12];
B= [10 30 30 40 50 60 ] ;
sum(B(A<4))
sum(B(A >4 & A<9))
sum(B(A>9))