how to concatenate matrix horizontally for a large number of matrices in a for loop

조회 수: 2 (최근 30일)
For example,
I am doing data analysis of a matrix of A whose dimension is 175x90. Since I analyze this dataset one by one such that A(:,1), A(:,2)...A(:,90). In the end, I hope I could still obtain a matrix of of B whose dimension is also 175x90. So I decided to use "horzcat" command such that B=horzcat(A(:,1), A(:,2)...A(:,90)). However, since there could be a really large number for me to concatenate, how can I achieve this in a loop rather than do this manually?
Thank you so much!
  댓글 수: 2
Taoooooooooooo
Taoooooooooooo 2019년 3월 1일
Hi Walter,
Thanks for answering. However, since I was supposed to anaylize the data one by one, and the final output becomes (175x1) instead (175x90). Therefore, I need a for loop to combine them back to the same dimension of the original file.
Tao

댓글을 달려면 로그인하십시오.

답변 (1개)

Walter Roberson
Walter Roberson 2019년 3월 1일
numrow = size(A,1);
numcol = size(A,2);
B = zeros(numrow, numcol)
for column = 1 : numcol
this_column = A(:,column);
.....
this_result = ...
B(:,column) = this_result;
end

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by