Filter löschen
Filter löschen

Matrix manipulation: update columns from stored variables

2 Ansichten (letzte 30 Tage)
ARP
ARP am 17 Mär. 2017
Kommentiert: Star Strider am 17 Mär. 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

Akzeptierte Antwort

Star Strider
Star Strider am 17 Mär. 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 Kommentare
ARP
ARP am 17 Mär. 2017
How do I tell to Matlab to count how many variables do I have?
Star Strider
Star Strider am 17 Mär. 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.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Get Started with MATLAB finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by