column multiplication by specific number with some condition
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
/matlabcentral/profile/authors/13737395
am 14 Nov. 2018
Kommentiert: madhan ravi
am 15 Nov. 2018
r = -5 + (5+5)*rand(10,1) % column with positive and negative numbers
I want to create the function r_1 by satisfying the following:
r_1= r .* 0.5 if r >0
and
r_1 = r .* 0.7 if r<0
I guess, I should multiply positive values by 0.5 and negative values by 0.7.
0 Kommentare
Antworten (1)
madhan ravi
am 15 Nov. 2018
Bearbeitet: madhan ravi
am 15 Nov. 2018
r_1=ones(1,numel(r)):
r_1(r>0)=r(r>0).*.5;
r_1(r<0)=r(r<0).*.7;
r_1
2 Kommentare
/matlabcentral/profile/authors/13737395
am 15 Nov. 2018
Bearbeitet: /matlabcentral/profile/authors/13737395
am 15 Nov. 2018
Siehe auch
Kategorien
Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!