Thread Subject: How to access variable generated by genvarname

Subject: How to access variable generated by genvarname

From: Sam

Date: 19 Nov, 2009 15:31:19

Message: 1 of 2

Hii

I am stuck in a seemingly small problem.
In a loop i am generating variables using the function genvarname.
I want to access these variables e.g. displaying them as an image
the simple discription is as follows

for i =1:10
var = genvarname(str);
eval([var '=mat(1:10,1:10)']);
imtool(var???(not working)), imashow, plot...??????
end

thnx in advance
sam

Subject: How to access variable generated by genvarname

From: Donn Shull

Date: 19 Nov, 2009 18:51:19

Message: 2 of 2

"Sam " <saurabh_biomed@yahoo.co.in> wrote in message <he3oc7$10r$1@fred.mathworks.com>...
> Hii
>
> I am stuck in a seemingly small problem.
> In a loop i am generating variables using the function genvarname.
> I want to access these variables e.g. displaying them as an image
> the simple discription is as follows
>
> for i =1:10
> var = genvarname(str);
> eval([var '=mat(1:10,1:10)']);
> imtool(var???(not working)), imashow, plot...??????
> end
>
> thnx in advance
> sam

Hi Sam,

I am not sure why you are doing this but in your codevar is a string generated by genvarname. After the eval statement there exists a new variable in the workspace with the name from var which has the value you assigned to it, but var is still just a string containing the name of the variable. If you want to use imtool on the data contained in the variable that was named by the string in var you could use:

imtool(eval(var));

or you could capture the output of your first eval:

temp = eval([var '=mat(1:10,1:10)']);
imtool(temp);

Hope this helps,

Donn

Tags for this Thread

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

rssFeed for this Thread

Contact us at files@mathworks.com