Effacer les filtres
Effacer les filtres

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

2 vues (au cours des 30 derniers jours)
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

Réponse acceptée

Image Analyst
Image Analyst le 18 Déc 2018
Modifié(e) : James Tursa le 19 Déc 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 commentaires
raghavendra kandukuri
raghavendra kandukuri le 19 Déc 2018
Thank you, @Image Analyst,Elijah,James

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by