help-octave
[Top][All Lists]
Advanced

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

How do I read a variable name file?


From: John W. Eaton
Subject: How do I read a variable name file?
Date: Thu, 31 Jul 2008 22:00:13 -0400

On 31-Jul-2008, Rubén Roa-Ureta wrote:

| Hi:
| 
| I want to read text files that contain a single number but whose names 
| changes according to user input, as in:
| 
|  >Yr=input('Year :');
| Yr: 1990
|  >filename=['SEPM_',num2str(Yr),'s2.txt']
| filename = SEPM_1990s2.txt
|  >eval(eggstart=['load ',filename])
| 
| However, the single number in SEPM_1990s2.txt hasn't been assigned to 
| eggstart
| 
|  >eggstart
| eggstart = load SEPM_1990s2.txt
| 
| whereas if I directly do the loading
| 
|  >eggstart = load SEPM_1990s2.txt
| eggstart =  the  single number in SEPM_1990s2.txt
| 
| the number is assigned.
| 
| What else should I do with the eval function to actually complete the 
| assignment?

You don't need eval for this job.  Use something like

  eggstart = load (sprintf ("SEPM_%ds2.txt", Yr));

jwe



reply via email to

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