Loop and numeric comparison
2 views (last 30 days)
Show older comments
Hello
i want to compare a value with the last n values and see if its the highest than the last n. I have tried to do a function like this
function varargout = close(Price, NumberofDays)
for j = NumberofDays : NumberofDays : size(Price)
for i = 1:size(Price)
if i ~= j
if Price(j) > Price(j-i)
msgbox('ok')
else
msgbox('ko')
end
else
break
end
end
end
end
The comparison is not coded yet, I am just making sure its targeting the right values. but unfortunately I am having an issue when it goes out of the inside loop and increment for the first time. For example
let say i want to compare Value 5 with the last 5 values
j will be equal to 5 then i will be incrementing on i, which will go from 1 to 4 when its 5, it will quit the loop and increment for the first time for j, but on the second, I will want Value 10(j) to be compared to Value 5, then 6,7,8,9, but its re starting from 1. I know my code is written to do this but I cant find a way to make it after each j loop to start from the last j of the previous loop. I dont know if i am clear .
Thank you very much
D
0 Comments
Answers (0)
See Also
Categories
Find more on Variables 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!