Thread Subject: how to name a vector with a variable name to store previous results

Subject: how to name a vector with a variable name to store previous results

From: Jose

Date: 7 Nov, 2009 22:33:01

Message: 1 of 4

Hello,
I have been tryiing to defene a vector which has to have a diferent name acording to some variables, in order to keep the results from previous results,

let say for example, I am studying the effect of 3 variables in a process, then:
from previous calculations I have all the results for each case, made by loops,, now I need to store all this reults in a vecto wich the name is denined by the correpondent case:

let say, the variables are "i", "j" and "k",
then for example when i=2, j=5 and k=7, the result from previous calculations is

result = [23 34 45 56 78]

I can create the name like this:
for i = 1:imax
  for j=1:jmax
    for k = 1:kmax
       name = sprintf (result_j%d_j%d_k%d',[i j k])
    end
   end
end

.. Now, how can I define that "name" is equal to the vector "result" ???
  
to finally get, for example:
                        result_i2_j5_k7 = [23 34 45 56 78]

Thank you very much for you help,
Regards.
       

Subject: how to name a vector with a variable name to store previous

From: Chan Huntington

Date: 7 Nov, 2009 23:21:04

Message: 2 of 4

Hi Jose,

If i understand your question correctly, you should be able to use 'eval', which concatenates a string and evaluates it as an expression. From your description:

>> eval(['result_i', num2str(i),'_j',num2str(j),'_k',num2str(k),' = [23 34 45 56 78]'])

You might also find the function genvarname to be useful. Best,
Chan

Subject: how to name a vector with a variable name to store previous

From: Jose

Date: 8 Nov, 2009 01:35:05

Message: 3 of 4

Hi Chan,

Thank you very much for your reply, it works perfectly!!
Than you so much!!

kind regards.

Subject: how to name a vector with a variable name to store previous results

From: Steven Lord

Date: 8 Nov, 2009 23:21:20

Message: 4 of 4


"Jose " <mylordjose@hotmail.com> wrote in message
news:hd4sit$f6r$1@fred.mathworks.com...
> Hello,
> I have been tryiing to defene a vector which has to have a diferent name
> acording to some variables, in order to keep the results from previous
> results,

DO NOT DO THIS.

See Q4.6 in the newsgroup FAQ for some of the reasons why you shouldn't and
some of the alternatives.

--
Steve Lord
slord@mathworks.com
comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ

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