How to state that at least 80% of the values in my vector need to be positive

2 vues (au cours des 30 derniers jours)
Lois Slangen
Lois Slangen le 12 Juil 2019
Commenté : Image Analyst le 12 Juil 2019
Hi, I have data with 10 frames per second and 180 seconds, which leaves me with a row vector of 1800 values, which can be positive or negative.
If all the values are negative, it needs to say "no positive values". If all the values are positive, it needs to say "no negative values".
if there are both negative and positive values then I want to find out if, after the first 15 seconds (so after first 150 values in my vector), atleast 80% of those values are positive. If yes, then I want to find the index of the first postive value. If no, then it needs to say "less than 80% positive"

Réponses (1)

Guillaume
Guillaume le 12 Juil 2019
if mean(yourvector(150:end) > 0) >= 0.8 %assuming positive means strictly greater than 0
startindex = find(yourvector(150:end) > 0, 1) + 149;
else
disp('less than 80% positive')
end
  1 commentaire
Image Analyst
Image Analyst le 12 Juil 2019
Building...
if max(yourvector) < 0
fprintf('Failed: No positive values were found! (All were negative)\n');
elseif min(yourvector) >= 0
fprintf('Success: No values are negative. (All are zero or positive).\n');
end

Connectez-vous pour commenter.

Catégories

En savoir plus sur Clocks and Timers dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by