필터 지우기
필터 지우기

Matrix manipulation: update columns from stored variables

조회 수: 2 (최근 30일)
ARP
ARP 2017년 3월 17일
댓글: Star Strider 2017년 3월 17일
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에서 Get Started with MATLAB에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by