How to change variable size(s) with timers without causing errors?
Mostrar comentarios más antiguos
Hello -
I am trying to run a simple timer function which runs every 10 seconds to monitor position(s) in the stock market. More specifically, I have created a variable called tradeFlag, which initializes as an empty variable ([]) and takes the value 1 if a trade is executed. What I am trying to do is prevent another trade from being executed by using simple if statements, like below:
tradeFlag = [];
function timer(hObj, eventdata, tradeFlag)
if isempty(tradeFlag) & % a market event happens
% submit order
assignin('base','tradeFlag',1)
end
end
However when I run this function, I either get a "Not enough input arguments error" or or an else block will not be executed. Is there a better way to do this? What am I missing here?
Many thanks!!
3 comentarios
Ajay Kumar
el 1 de Oct. de 2019
Can you update full code? including the timer function.
BuMatlab
el 1 de Oct. de 2019
Guillaume
el 1 de Oct. de 2019
In order to understand the not enough input argument error, we would need the full text of the error message and at the very least the code thar creates the timer (and its properties if it's done on several lines).
"or an else block will not be executed" For that we would need to see the full if...else block.
"What I am trying to do is prevent another trade from being executed" What does a trade being executed actually mean in terms of code?
Respuestas (1)
Steven Lord
el 1 de Oct. de 2019
0 votos
It depends on how you set the timer object's TimerFcn property.
Rather than depending on a variable in the base workspace, based on the limited description of what you're trying to do I would probably store the data in the UserData property of the timer object (which is passed into its TimerFcn as the first input.)
2 comentarios
Guillaume
el 1 de Oct. de 2019
The callback that you show above doesn't match at all the function in your question.
Categorías
Más información sobre Startup and Shutdown en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!