Easiest way of Renaming Vectors
Mostra commenti meno recenti
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
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
Oleg Komarov
il 1 Ago 2012
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
il 1 Ago 2012
Walter Roberson
il 1 Ago 2012
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
il 1 Ago 2012
Modificato: Walter Roberson
il 2 Ago 2012
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.
Walter Roberson
il 2 Ago 2012
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
il 2 Ago 2012
Categorie
Scopri di più su Structures in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!