フィルターのクリア

I want only one value stored in this code

2 ビュー (過去 30 日間)
Folakemi Omotoye
Folakemi Omotoye 2018 年 8 月 1 日
編集済み: Dennis 2018 年 8 月 2 日
I want to store a particular value in this loop, how can i do it please. the code is below
for t=1:1:30
s(t)=sum(v(t))+sum(v(1:t));
g(t)=v(t) - min(v(1:t));
if s(t) > 4
disp(t) %%%%%%%%line of interest
disp(v(t)) % if cumulative sum is greater than 4,note and display time of change
end
end
in the code above, the line (line of interest) displays the outcome of every iteration but i need it to only display the value of time t and the corresponding value of vector v when the threshold (4) is exceeded.
  4 件のコメント
Walter Roberson
Walter Roberson 2018 年 8 月 2 日
If that is your code, then the explanation would have to be that s(t) is greater than 4 for each of those iterations.
Did you want to know only the first time it happens? Do you want to stop calculating s when it happens, or do you want to continue calculating s but only display those values the first time it happens?
Folakemi Omotoye
Folakemi Omotoye 2018 年 8 月 2 日
to continue calculating s but display each time it exceeds 4

サインインしてコメントする。

採用された回答

Dennis
Dennis 2018 年 8 月 2 日
編集済み: Dennis 2018 年 8 月 2 日
Does v actually contain negative values? Else every value in s will be greater 4 after it exceeds this threshold for the first time. Code below displays the first value of t and v(t) when this happens (needs adjustment if you want to change the increment of the loop).
for t=1:1:30
s(t)=sum(v(1:t));
g(t)=v(t) - min(v(1:t));
end
idx=find(s>4,1)
disp(v(idx));
  4 件のコメント
Folakemi Omotoye
Folakemi Omotoye 2018 年 8 月 2 日
understood.thanks for the code
Dennis
Dennis 2018 年 8 月 2 日
編集済み: Dennis 2018 年 8 月 2 日
You are welcome

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeImages についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by