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

1 view (last 30 days)
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"

Answers (1)

Guillaume
Guillaume on 12 Jul 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 Comment
Image Analyst
Image Analyst on 12 Jul 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

Sign in to comment.

Tags

Community Treasure Hunt

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

Start Hunting!