From: Paul Alexander on 7 Apr 2010 17:22 I'm writing a simple script to streamline creating some variables. To do it I'm using the function 'eval' to create my different variables. I know it's preferable to use arrays but I'm not. This is how I'm using eval: temp=eval(['region' num2str(1)]) Then matlab prints: ??? Index exceeds matrix dimensions. I've also tried: eval(['temp'='region' num2str(i)]) To which matlab prints: ??? eval(['temp'='region' num2str(i)]) | Error: The expression to the left of the equals sign is not a valid target for an assignment. So I thought I'd use "help eval", where matlab gives the example: for n = 1:12 eval(['M' num2str(n) ' = magic(n)']) end But when you run that you get the error:??? Index exceeds matrix dimensions. This lead me to believe there must be something wrong. Any ideas? By the way I've never tinkered or altered my built-in matlab functions in any way.
From: TideMan on 7 Apr 2010 17:32 On Apr 8, 9:22 am, "Paul Alexander" <psalexan...(a)alaska.edu> wrote: > I'm writing a simple script to streamline creating some variables. To do it I'm using the function 'eval' to create my different variables. I know it's preferable to use arrays but I'm not. > > This is how I'm using eval: temp=eval(['region' num2str(1)]) > Then matlab prints: ??? Index exceeds matrix dimensions. > > I've also tried: eval(['temp'='region' num2str(i)]) > To which matlab prints: > ??? eval(['temp'='region' num2str(i)]) > | > Error: The expression to the left of the equals sign is not a valid target for an > assignment. > > So I thought I'd use "help eval", where matlab gives the example: > for n = 1:12 > eval(['M' num2str(n) ' = magic(n)']) > end > But when you run that you get the error:??? Index exceeds matrix dimensions. > > This lead me to believe there must be something wrong. Any ideas? > By the way I've never tinkered or altered my built-in matlab functions in any way. Here is the key statement: "I know it's preferable to use arrays but I'm not." So, you know what you are doing is wrong, but you are doing it anyway. How stupid is that? I stopped reading your post at that point.
From: Matt J on 7 Apr 2010 17:38 "Paul Alexander" <psalexander(a)alaska.edu> wrote in message <hpit1s$lsd$1(a)fred.mathworks.com>... > I'm writing a simple script to streamline creating some variables. To do it I'm using the function 'eval' to create my different variables. I know it's preferable to use arrays but I'm not. > > This is how I'm using eval: temp=eval(['region' num2str(1)]) > Then matlab prints: ??? Index exceeds matrix dimensions. ================ Odds are that you created (accidentally or otherwise) an empty matrix variable called num2str in your workspace. MATLAB sees the expression num2str(1) and thinks you are trying to index this matrix. > I've also tried: eval(['temp'='region' num2str(i)]) > To which matlab prints: > ??? eval(['temp'='region' num2str(i)]) > | > Error: The expression to the left of the equals sign is not a valid target for an > assignment. ============= Because the = sign isn't enclosed in quotes. > > So I thought I'd use "help eval", where matlab gives the example: > for n = 1:12 > eval(['M' num2str(n) ' = magic(n)']) > end > But when you run that you get the error:??? Index exceeds matrix dimensions. ======= Again, MATLAB thinks num2str is a matrix.
From: Walter Roberson on 7 Apr 2010 17:41 Paul Alexander wrote: > I'm writing a simple script to streamline creating some variables. To do > it I'm using the function 'eval' to create my different variables. I > know it's preferable to use arrays but I'm not. > > This is how I'm using eval: temp=eval(['region' num2str(1)]) > Then matlab prints: ??? Index exceeds matrix dimensions. The appearance is as if Matlab thinks you have a variable named 'eval', or else a variable named 'num2str'. Try using the who() and which() command to double-check. > I've also tried: eval(['temp'='region' num2str(i)]) > To which matlab prints: ??? eval(['temp'='region' num2str(i)]) > | > Error: The expression to the left of the equals sign is not a valid target > for an assignment. The '=' has to be quoted as well. eval(['temp=region', num2str(i)])
From: Paul Alexander on 8 Apr 2010 14:40 Walter Roberson <roberson(a)hushmail.com> wrote in message <hpiu6v$4k6$1(a)canopus.cc.umanitoba.ca>... > Paul Alexander wrote: > > This is how I'm using eval: temp=eval(['region' num2str(1)]) > > Then matlab prints: ??? Index exceeds matrix dimensions. > > The appearance is as if Matlab thinks you have a variable named 'eval', or > else a variable named 'num2str'. Try using the who() and which() command to > double-check. > Thanks you were right; I did have an 'eval' variable. Chalk another one up to bonehead mistakes.
|
Pages: 1 Prev: Help!! Error -----> le Matrix dimensions do not match Next: error using dicominfo |