For Programmers: Free Programming Magazines  


Home > Archive > Matlab > April 2005 > Renaming variable per user input









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Renaming variable per user input
Tom Irvine

2005-04-23, 3:59 pm

There must be an easy answer to this question.

1. I have a matrix called 'a' that has some numerical data.

2. I want to use the 'input' command to prompt the user for a new
name for matrix 'a'.

Here is my code so far, but it needs modification.

new_name=input(' ','s')
new_name=a

How can I modify the code to meet the goal?

Thank you,
Tom Irvine
Jiro Doke

2005-04-23, 3:59 pm

Tom Irvine wrote:

> new_name=input(' ','s')


eval([new_name '=a;']);

jiro
Anders Björk

2005-04-23, 3:59 pm

assignin is much much better if it works in the context. eval should be
avoided. Using eval if can not be avoided is ok otherwise it is slopy matlab
programming.
help assignin

"Jiro Doke" <jdokeh@umich.edu> skrev i meddelandet
news:ef03c4d.0@webx.raydaftYaTP...
> Tom Irvine wrote:
>
>
> eval([new_name '=a;']);
>
> jiro



Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com