help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: string to variable?


From: Vergil Mueller
Subject: Re: string to variable?
Date: Mon, 4 Sep 2006 12:31:54 -0600

Gosh, I never knew there were so many ways to do something like this.  I think for my purposes, the eval() function will work fine.  I'll keep this method in mind though, too.

On 9/4/06, Bill Denney <address@hidden> wrote:
On Mon, 4 Sep 2006, the_verge wrote:

> I was wondering if there is a way to assign a value to a variable, and then
> construct a string with the same characters as the variable, and then use it
> to access the value of the original variable.  For Example:
>
> thing_a = 2;
>
> x = "thing_a";
> %code here to merge the string "thing_a" with the variable thing_a
> x
>
> My hope is that running this script would return
>
> x = 2
>
> Is there a way to do this?

It sounds like you're wanting to do something that would work better with
structures (eval usually ends up causing headaches later).  Might
something like this work for you:

string = "thing_a";
value = 2;
x.(string) = value;

Now, x.thing_a is set equal to 2.

Bill

--
"You couldn't fill a 128-bit storage pool without boiling the oceans."
   -- Jeff Bonwick, http://www.sun.com/2004-0914/feature/




--
Vergil Mueller
(541) 231- 8596
reply via email to

[Prev in Thread] Current Thread [Next in Thread]