How to concatenate matrices using for loop?

조회 수: 1 (최근 30일)
Abdulaziz Abutunis
Abdulaziz Abutunis 2017년 12월 8일
댓글: Abdulaziz Abutunis 2017년 12월 9일
Dear All:
I have a group of matrices of size (100X3). If possible, I want to concatenate them in one larger matrix using a for a loop. I want to use a loop because the number of matrices differs for each run so using the command [ x1 x2 ...] is not practical.
Thank you, Aziz
  댓글 수: 2
James Tursa
James Tursa 2017년 12월 9일
How are the individual matrices stored? In individual variable names like x1, x2, etc.? Or in a cell array? Or as fields of a struct? Or ...?
Abdulaziz Abutunis
Abdulaziz Abutunis 2017년 12월 9일
Thank you for the respond. The are stored such as x{1}, x{2}..... each has the same size 68*3 elements
Thanks again

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

채택된 답변

James Tursa
James Tursa 2017년 12월 9일
If x is a cell array, and you simply want all of them, then
result = cell2mat(x);
or if you want them stacked vertically
result = cell2mat(x');
If you want a subset of the cells, then specify the range. E.g.,
result = cell2mat(x(range));
or if you want them stacked vertically
result = cell2mat(x(range)');
  댓글 수: 1
Abdulaziz Abutunis
Abdulaziz Abutunis 2017년 12월 9일
Wow it did exactly what i want in an easy way, thank you so much James Tursa

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by