Re: how to clear a variable whose name is located in a string?



Not the nicest way, but:

whos
Name Size Bytes Class
chicken 1x3 24 double array
filename 1x7 14 char array
Grand total is 10 elements using 38 bytes
eval(['clear ' filename])
whos
Name Size Bytes Class
filename 1x7 14 char array
Grand total is 7 elements using 14 bytes



hth



"Anish Patel" <iceapatel@xxxxxxxxxxx> wrote in message
news:20420268.1155048942396.JavaMail.jakarta@xxxxxxxxxxxxxxxxxxxxxxxxx
For example:

filename=input('enter name of file to load: ",'s')
% eg: user inputs 'chicken'
filename2=[filename '.txt']
load(filename2, 'ascii')
% now matlab has loaded a numeric matrix called 'chicken'

After doing stuff with the variable, I now want to clear it from memory
(since its a big file) before loading another file to analyze.

At this point I have 2 variables: [1] string variable -->
filename='chicken' and a numeric variable --> chicken=[1 2 3]

I want to clear the numeric variable 'chicken', but the name of the
variable is located in the string 'filename' (as input by the user).

I tried:
clear(filename) % only clears the string, not the numbers
clear(eval(filename)) % doesn't work either

Any ideas?

Thanks,
Anish


.



Relevant Pages