Matrix manipulation: update columns from stored variables

1 vue (au cours des 30 derniers jours)
ARP
ARP le 17 Mar 2017
Commenté : Star Strider le 17 Mar 2017
Suppose I have a set of variables (15) as column vectors, called A from 1-15. Now I would like to make a matrix of all those variables. They have 12501 rows if that helps.
I thought about creating first a zeros matrix (12501,15), and then append each column with my variables.
is there other way to do it? I read about cell2mat but I don't get it. I am truly beginner..
How could I do it in a loop for n variables?
Any help will be very appreciated! Thanks

Réponse acceptée

Star Strider
Star Strider le 17 Mar 2017
‘I have a set of variables (15) as column vectors, called A from 1-15’
If they are ‘A1’, ‘A2’, ... ‘A15’, and you only need to do this once, just type it manually:
A_Matrix = [A1 A2 A3 A4 A5 ... A15];
I will let you fill in the others.
Then save it as a ‘.mat’ file so you can simply load it when you need it.
  2 commentaires
ARP
ARP le 17 Mar 2017
How do I tell to Matlab to count how many variables do I have?
Star Strider
Star Strider le 17 Mar 2017
I was thinking that if you only had 15 vectors, you could just type them in.
If you want to program it, this will probably work:
N = 15; % Number Of ‘A’ Vectors
A_Matrix = zeros(12501,N);
for k1 = 1:N
A_Matrix(:,k1) = eval(sprintf('A%d',k1));
end
Note This is UNTESTED CODE. It should work.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Get Started with MATLAB dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by