Matrix manipulation: update columns from stored variables

1 次查看(过去 30 天)
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

采纳的回答

Star Strider
Star Strider 2017-3-17
‘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 个评论
ARP
ARP 2017-3-17
How do I tell to Matlab to count how many variables do I have?
Star Strider
Star Strider 2017-3-17
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.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by