Matlab: using a string as condition for if statement -


cond = 'a==1'; a=1; if (cond) b=0; end 

hi! there way thing wrote above? in text variable need write condition (even complex one, using && , || too) , in if statement insert variable. tried example sadly didn't work. can solve it?

edit: more information you!
backtesting different trading strategies project.
inside general m-file, make use of function each strategy need tests. each strategy gets in input data current situation , function evaluates behavior of trading strategy according data (and according margin requirements , other stuff independent strategy). thing different in each function, entry or exit rule. each strategy has sure entry , exit condition (for instance, "open long position when ... , ..." or "close short position when ... or ...").
in main m-file using cycle simulate time passing by, want implement further external cycle represents number of strategy tested. furthermore, each condition in if-statements written hand , obtain unique function (no more 1 each strategy now) according cycle index of strategy, pass entry , exit conditions taken matrix of strings.

i hope possible that.

i think want:

cond = 'a==1'; a=1; if eval(cond)   b=0; end 

however, eval evil. try not use if possible: http://blogs.mathworks.com/loren/2005/12/28/evading-eval/


Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -