Easiest way of Renaming Vectors

One of the functions I'm using is giving me vectors whose name format is myc1_L, myc2_L, myc3_L ... myc99_L . Is there an easy way to rename them as A1 A2 A3 ...A99 ?

Risposte (1)

Walter Roberson
Walter Roberson il 1 Ago 2012

0 voti

Why? If you are doing it to try to match the example variable names of the FAQ, you are probably doing the wrong thing. Better to convert it all to a cell array.

7 Commenti

As I commented in John's previous post, he has same size matrices, and I recommended to use a 3D array.
@John, have you tried the solutions in the FAQ or mine?
John
John il 1 Ago 2012
I want to concatenate the arrays horizontally, C = horzcat(A1, A2, ...).
Put them in a cell array, A{1}, A{2}, A{3}, and so on, and then
C = [A{:}];
However, Oleg's comment suggests that what you will end up wanting is
C = cat(3, A{:});
John
John il 1 Ago 2012
Modificato: Walter Roberson il 2 Ago 2012
I started using Matlab this week. Still trying to figure it out. I have a function
K = RipleysK(myc,distance,box,1);
where I'm using the loop below to calculate L for myc1, myc2....
c = who('myc*','-global');
for i = 1:size(c,1);
C = eval(cell2mat(c(i)));
K = RipleysK(C,distance,box,1); % Function to be looped
d =(1:rmax); r=d';
L =(sqrt(K/pi)-r);
eval([cell2mat(c(i)) '_L' '=L']);
end
The results are named myc1_L, myc2_L......how can I edit it to rename them A1,A2,.....
Oleg Komarov
Oleg Komarov il 2 Ago 2012
Modificato: Oleg Komarov il 2 Ago 2012
You DO NOT have to rename them to A1,A2 etc... but use a cell array, a structure, or a 3D array.
How did you generate myc* in the first place? Please post the code so that we can give you the right setting.
Replace your line
eval([cell2mat(c(i)) '_L' '=L']);
with
eval( sprintf('A%d = L', i) );
This will do what you asked, rename to A1, A2, etc.. Please go ahead and try it, and get back to us once you prove to yourself that this is not a useful thing to do.
John
John il 2 Ago 2012
Thanks, it worked. Hopefully I will be able to use easier ways as I continue learning the MATLAB basics.

Accedi per commentare.

Richiesto:

il 1 Ago 2012

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by