Conditional matrix arrangement in output

1 view (last 30 days)
Hello every one my problem is in output.
z=[6
21
36]
but ı want to z as
z=[4
21
12]
how can ı fix this problem.Thanks for your answer and the file Untitled2.m uploaded.

Accepted Answer

KSSV
KSSV on 5 May 2021
x=[1 2 3 4 5
6 7 8 9 10
11 12 13 14 15];
a=1;
b=2;
c=3;
z = zeros(3,1) ;
idx = x(:,1)<3 ;
z(idx) = x(idx,2)*b ;
idx = x(:,1) >= 3 & x(:,1) < 7 ; % 3<= x(:,1)<7
z(idx) = x(idx,2)*c ;
idx = x(:,1) > 7 ;
z(idx) = x(idx,2)*a ;

More Answers (0)

Products

Community Treasure Hunt

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

Start Hunting!