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

조회 수: 3 (최근 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