tags:

views:

25

answers:

2

Hi all, eval() returns the same error, even with the simplest of inputs.

>> ns=int2str(17)
>> xs=num2str(18)
>> d = eval(ns,'+',xs)
??? Index exceeds matrix dimensions.
>> eval('1/2')
??? Index exceeds matrix dimensions.

Any help would be appreciated.

A: 

I think you need to put the argument in square brackets. That's the syntax shown in the documentation - see http://www.math.ufl.edu/help/matlab/tec1.3.html or http://www.mathworks.com/access/helpdesk/help/techdoc/ref/eval.html

I don't have matlab, but in freemat,

--> ns='12'
ns =
12
--> xs='14'
xs =
14
--> d=eval([ns,'+',xs])
d =
 26
--> d
ans =
 26
--> d=eval(ns,'+',xs)
Error: Too many inputs to function eval
Cole
I've tried that, and other variations...>> d=eval([ns,'+',xs])??? Index exceeds matrix dimensions.
caglarozdag
maybe just try restarting matlab next time?
Cole
+4  A: 

try clear all first.. it seems you have a variable called eval that is shadowing the function.

>> eval = 1;
>> which -all eval
eval is a variable.
built-in (C:\Program Files\MATLAB\R2010a\toolbox\matlab\lang\@char\eval)  % Shadowed char method
C:\Program Files\MATLAB\R2010a\toolbox\matlab\lang\@opaque\eval.m         % Shadowed opaque method
C:\Program Files\MATLAB\R2010a\toolbox\stats\@classregtree\eval.m         % Shadowed classregtree method
Amro
maybe just `clear eval` if you dont want to lose your workspace :)
Amro

related questions