column multiplication by specific number with some condition
3 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(1 个)
madhan ravi
2018-11-15
编辑:madhan ravi
2018-11-15
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 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!