to expand it a bit more. what is going on with your result = eval(string) is exactly how it is written.
you're setting everything within the string into the result which doesn't compute. so in essence you're typing (which won't work)
>> result = a=25,if (a == 30),a = 75;,else,a =42,end,37
which doesn't get you result = 37
What you could do just like you did with your fprintf statement
just do:
sprintf('a=25\nif (a == 30)\n a = 75;\nelse\n a =42\nend\n37')
eval(ans)
result = ans
Best Answer