how to merge two mat files which have different structure cells into a mat file with a matrix
    조회 수: 7 (최근 30일)
  
       이전 댓글 표시
    
I need to merge 1000 files with different structure cells into one matrix. For detailed, I make an examples of two files A and B files. File A has one row with n cells A = {cell(1a,1a), cell(1a,2a), .... cell(1a,na)} and B has one row and m cells B = {cell(1b,1b), cell(1b,2b), .... cell(1b,mb)}. Each cell in A and B has same 3 columns but different rows. My question is how to merge these two files with a transformation of all cell content in to ONE matrix mat file like: [cell(1a,1a); cell(1a,2a); .... cell(1a,na); cell(1b,1b); cell(1b,2b), .... cell(1b,mb)] Thanks.
댓글 수: 2
  jgg
      
 2015년 12월 22일
				I think you need to give us a clearer example of what you're trying to do. Let's say you have K files. Then, if I understand your problem, couldn't you just do this:
 C = cell(K,1);
 for i = 1:K
   load(file_i);
  C{i} = file_i;
 end
Is this not what you want to do?
채택된 답변
  Renato Agurto
      
 2015년 12월 22일
        
      편집: Renato Agurto
      
 2015년 12월 22일
  
      I think this should do it:
 for i = 1:N
   A = load(file_i);
   A = struct2cell(A);
   f{i} = cat(1,A{:})
 end
 combined_f = cat(1,f{:});
댓글 수: 3
  Renato Agurto
      
 2015년 12월 22일
				
      편집: Renato Agurto
      
 2015년 12월 22일
  
			My answer was arlready for multiple files. file_i should actually be file_array{i}. where
 file_array = {'file1.mat',..
                'file2.mat',...
                'file3.mat'};
then you can use the above code:
 for i = 1:N
   A = load(file_array{i}); %load file i
   A = struct2cell(A); %get cell array with ALL matrices in file
   f{i} = cat(1,A{:}) %merge matrices of file
 end
 combined_f = cat(1,f{:}); %merge matrices of all files
where N is the number of files. In this case 3
추가 답변 (1개)
참고 항목
카테고리
				Help Center 및 File Exchange에서 Data Type Conversion에 대해 자세히 알아보기
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!



