How to check if all the values in the array are greater or equal or lesser than a particular value?

534 ビュー (過去 30 日間)
In the first IF loop, i want to check if any of the values in SPEED(SPEED is an array holding 72000 values) are greater than max(num1), if so then visit the second IF loop just for that particular value of SPEED array not for for all the values. And in the second IF loop, i want to check if any of the values of TCADJUSTEDPERCENTLOAD array(TCADJUSTEDPERCENTLOAD is an array holding 72000 values) is greater than interp1(finalized,final, SPEED) if so then AdjSpeed=interp1(final,finalized,TCADJUSTEDPERCENTLOAD) for that particular value of TCADJUSTEDPERCENTLOAD array. Else of first IF is AdjSpeed = SPEED.
i wrote the below code but it is just checking with the first value of SPEED and first value of TCADJUSTEDPERCENTLOAD not with rest 71999 values, any help is really apreciated, Thank you!!
if (SPEED > max(num1))
if (TCADJUSTEDPERCENTLOAD > interp1(finalized,final, SPEED))
AdjSpeed = SPEED
  2 件のコメント
raghavendra kandukuri
raghavendra kandukuri 2019 年 1 月 7 日
編集済み: raghavendra kandukuri 2019 年 1 月 7 日
appologies for that, Done



Jan 2019 年 1 月 7 日
It seems like you are confused by the term "if loop". The if command is not a loop.
if needs a scalar condition. If SPEED is a vector, this is evaluated implicitly:
if all(SPEED > max(num1))
You want to check all elements of SPEED, so you need a loop:
for k = 1:numel(SPEED)
if SPEED(k) > max(num1)
You need anotehr loop for TCADJUSTEDPERCENTLOAD also (by the way, this word is not readable - use a leaner name instead).
Do not evaluated e.g. max(num1) or interp1(finalized,final, SPEED) inside the loop, but before, to save processing time.
For more efficient code, logical indexing will help you:
match = (SPEED > max(num1));
Now e.g. SPEED(match) contains only elements of speed beyond the limit.

その他の回答 (0 件)

Community Treasure Hunt

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

Start Hunting!

Translated by