Combining multiple matrices into a single vector
조회 수: 15 (최근 30일)
이전 댓글 표시
Hi there,
have some matrices that I would like to combine into a single vector. For example:
T1 = [2 3;
4 2]
T2 = [1 7;
9 4]
T3 = [5 5;
1 4]
I do not want to add them together like it does here:
T = [T1 T2 T3]
Rather I want to store them is such a way that I can index them in a loop
How can I accomplish this?
Many thanks
댓글 수: 2
Katy
2023년 9월 29일
Hi Scott-
How do you want the final matrix to look? Can you provide an example of the desired final matrix?
Is it a single row? Or a combined matrix?
Thanks,
Katy
채택된 답변
추가 답변 (1개)
Katy
2023년 9월 29일
편집: Katy
2023년 9월 29일
If I am understanding the question correctly, here's one way to store them as a single vector (T_vec).
It requires storing the inputs in a cell array rather than separate matrices.
Let me know if this solves your question!
T{1,1} = T1;
T{2,1} = T2;
T{3,1} = T3;
T_vec = [];
for i = 1:length(T)
temp = T{i,1};
sz_temp = size(temp);
rows = sz_temp(1,1);
col = sz_temp(1,2);
for j = 1:rows
for p = 1:col
T_vec = [T_vec temp(j, p)];
end
end
end
참고 항목
카테고리
Help Center 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!