How to make sure all the elements in an array are less than certain value?

2 次查看(过去 30 天)
I have an array of type double (name= speed) and it has 72000 values, and i want to write a condition that if any of the elements in speed are less than '800' then do certain calculations, if it is greater than '800' then do certain caluclations

采纳的回答

Image Analyst
Image Analyst 2018-12-18
编辑:James Tursa 2018-12-19
Let's say you want to multiply by 2 if less than 800, and divide by 4 otherwise. Create a mask, then do the assignment of the new values.
mask = speed < 800;
speed(mask) = speed(mask) * 2;
% ~mask (tilde mask) inverts mask and selects speed >= 800
speed(~mask) = speed(~mask) / 4; % fixed typo
  4 个评论

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by