How to vectorise this function

How to vectorize this function:
NumI = 0;
for i=1:100
if Value(i) < 10000
NumI = NumI +1;
end
end
Elements = zeros(5000, NumI);
%% Value - array of float values

回答 (2 件)

Stephan
Stephan 2020 年 11 月 17 日
編集済み: Stephan 2020 年 11 月 17 日

0 投票

NumI = sum(Value < 10000);
Elements = zeros(5000, NumI);
Andrei Bobrov
Andrei Bobrov 2020 年 11 月 17 日

0 投票

NumI = sum(Value(1:100) < 10000)

カテゴリ

ヘルプ センター および File ExchangeStartup and Shutdown についてさらに検索

製品

タグ

質問済み:

2020 年 11 月 17 日

編集済み:

2020 年 11 月 17 日

Community Treasure Hunt

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

Start Hunting!

Translated by