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 Center および File ExchangeClocks and Timers についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by