How to vectorise this function

1 次查看(过去 30 天)
Master Blabla
Master Blabla 2020-11-17
编辑: Stephan 2020-11-17
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
NumI = sum(Value < 10000);
Elements = zeros(5000, NumI);

Andrei Bobrov
Andrei Bobrov 2020-11-17
NumI = sum(Value(1:100) < 10000)

类别

Help CenterFile Exchange 中查找有关 Get Started with MATLAB 的更多信息

标签

产品

Community Treasure Hunt

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

Start Hunting!

Translated by