How can I combine 100+ matrices into a combined array for indexing

조회 수: 1 (최근 30일)
ShaneS
ShaneS 2016년 8월 15일
편집: ShaneS 2017년 8월 1일
Hello MATLAB experts,
I have a bunch of matrices (82 x 82), one for each research subject. How can I combine these matrices into a single .mat file so I can extract information about the matrices with a command such as: combined_matrices(5) to get the 82 x 82 matrix for subject number 5?
Thanks very much.

채택된 답변

Azzi Abdelmalek
Azzi Abdelmalek 2016년 8월 15일
편집: Azzi Abdelmalek 2016년 8월 15일
Use cell arrays
M={A1,A2,A3,A4,A5}
save filename M
To get the matrix for project N°5
A=M{5}
Since your matrices are same sizes, another alternative is to use a 3-D Matrix
M(:,:,1)=A1
M(:,:,2)=A2
.... % and so on
  댓글 수: 3
Azzi Abdelmalek
Azzi Abdelmalek 2016년 8월 15일
for k=1:10
file=sprintf('A%d',k)
A=load(file)
f=fieldnames(A)
M(:,:,k)=A.(f{1})
end
ShaneS
ShaneS 2016년 8월 15일
Thank you so much, Azzi!

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by