calculation of coordinates of the sum of values greater than 5
1 回表示 (過去 30 日間)
古いコメントを表示
there is a vector of large length, here is a small part of it F1 = [2.5 2.5 3.5 1 1 5.2 11.4 4 4 5.2 2 2 6] I need to get the coordinate values in this vector of all more than 5. I have a calculation code, but the F1 vector is too big and it takes a lot of time. Help me optimize the code.
ps. I specify all dimensions and create separately a region of zeros for all values
F1=[2.5 2.5 3.5 1 1 5.2 11.4 4 4 5.2 2 2 6]
Fzero=0;
Elemets=0;
j=0;
for i=1:length(F1)
Fzero=Fzero+F1(i);
Elemets=Elemets+1;
if Fzero>=5
j=j+1;
n(j)=Elemets;
psk(j)=Fzero;
Fzero=0;
Elemets=0;
end
end
% n =[2 3 1 1 2 1 3] % n i need to get
0 件のコメント
回答 (1 件)
Rohan Kale
2020 年 2 月 14 日
In my understanding you are trying to find the indices of values that are greater than 5. You can use the find function to actually optimize your code.
indices = find(F1 > 5);
That should solve your issue. I think the doc page on find will help you
参考
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!