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

조회 수: 2 (최근 30일)
Lois Slangen
Lois Slangen 2019년 7월 12일
댓글: Image Analyst 2019년 7월 12일
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"

답변 (1개)

Guillaume
Guillaume 2019년 7월 12일
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
Image Analyst
Image Analyst 2019년 7월 12일
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

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Clocks and Timers에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by