manipulation of seperate vector values
7 次查看(过去 30 天)
显示 更早的评论
so i have a vector set of values and wanted to round all the values to the nearest positive, even integer. and all the values less then zero are rounded to zero. any idea on how to do this using an mfile?
0 个评论
采纳的回答
更多回答(2 个)
Paulo Silva
2011-4-4
%v is your vector
idx=v<0; %get the index of all values lower than 0
idx1=v>0; %get the index of all values higher than 0
v(idx)=0; %substitute the lower than 0 values by 0
v(idx1)=round(v(idx1)) %substitute higher than 0 values by nearest positive
In case you want a special form of the round function that does nearest positive and even integer get the round2even function or round2
3 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!