calculation of coordinates of the sum of values greater than 5
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
Risposte (1)
Rohan Kale
il 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
Vedere anche
Categorie
Scopri di più su Optimization in Help Center e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!