A small digression from the main topic of this blog – dogs coding in C++ – to highlight a small portion of the ugliness in the MATLAB syntax.
Let’s assign a variable:
>> A = 2 A = 2 >> disp(A) 2 >> disp(eval('A')) 2
Ok, so A equals eval(‘A’). What about:
>> eval('B = 3') B = 3 >> disp(B) 3 >> disp(eval('B')) 3
Ok, what if…
>> eval('C') = 4 eval = Columns 1 through 20 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Columns 21 through 40 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Columns 41 through 60 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Columns 61 through 67 0 0 0 0 0 0 4
Wat?
Let’s double check the variables now…
>> disp(A) 2 >> disp(B) 3 >> disp(C) Undefined function or variable 'C'. >> disp(eval(C)) Undefined function or variable 'C'. >> disp(eval('C')) 4
WAT?!?
>> disp(eval('A')) 0 >> disp(eval('B')) 0
Wait, but…
>> eval eval = Columns 1 through 20 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Columns 21 through 40 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Columns 41 through 60 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Columns 61 through 67 0 0 0 0 0 0 4
…