How to make sure all the elements in an array are less than certain value?
4 views (last 30 days)
Show older comments
raghavendra kandukuri
on 18 Dec 2018
Commented: raghavendra kandukuri
on 19 Dec 2018
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
0 Comments
Accepted Answer
Image Analyst
on 18 Dec 2018
Edited: James Tursa
on 19 Dec 2018
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 Comments
More Answers (0)
See Also
Categories
Find more on Author Block Masks in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!