calculation of coordinates of the sum of values ​​greater than 5

2 views (last 30 days)
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

Answers (1)

Rohan Kale
Rohan Kale on 14 Feb 2020
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
  1 Comment
Lev Mihailov
Lev Mihailov on 14 Feb 2020
This is the problem, I need exactly the sum of the elements greater than 5
indices = find(F1 > 5);
indices=[6 7 10 13]
%and I need to follow the example
F1=[2.5 2.5 3.5 1 1 5.2 11.4 4 4 5.2 2 2 6]
n(1)=2.5+2.5=5 ; % n(1)=2
n2(2)=3.5+1+1>5 ; % n(2)=3
...
I did not find a team in the matlab that could do this automatically

Sign in to comment.

Products

Community Treasure Hunt

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

Start Hunting!