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!