MATLAB Answers

Conditional matrix arrangement in output

3 ビュー (過去 30 日間)
Omer Utku Altindag
Omer Utku Altindag 2021 年 5 月 5 日
回答済み: KSSV 2021 年 5 月 5 日
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.

採用された回答

KSSV
KSSV 2021 年 5 月 5 日
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 ;

その他の回答 (0 件)

Community Treasure Hunt

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

Start Hunting!

Translated by