I want only one value stored in this code
Show older comments
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 Comments
Aquatris
on 1 Aug 2018
Does S(t) go above multiple times? if so do you only want the first time it goes above? Share your whole code, with S and v variables, so we can have better understanding.
Folakemi Omotoye
on 2 Aug 2018
Walter Roberson
on 2 Aug 2018
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
on 2 Aug 2018
Accepted Answer
More Answers (0)
Categories
Find more on Image Segmentation and Analysis in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!