Convert 3-D matrix to a table
    14 ビュー (過去 30 日間)
  
       古いコメントを表示
    
    Konstantinos Tsitsilonis
      
 2017 年 9 月 11 日
  
    
    
    
    
    コメント済み: Konstantinos Tsitsilonis
      
 2017 年 9 月 11 日
            Hi all,
I have an output from a for loop which is a 3-D matrix. I would like to place the contents of that 3-D matrix in a table such that if my 3-D matrix is
 Mat = rand(5, 10, 4) ;
My table can look like this:
 Var1 = reshape(Mat(:,1,:), [], 2) ; %Table Variables extracted and converted to 2-D matrices
 Var2 = reshape(Mat(:,2,:), [], 2) ;
 etc....
 T = table(Var1, Var2 ... etc)
This way, under each variable there are going to be four columns.
Is there an 'automated' way to perform the above, as depending on the problem I am going to be dealing with anywhere from 2-4 'layers' on the 3rd dimension of the matrix Mat ?
Thanks for your responses in advance,
KMT.
0 件のコメント
採用された回答
  Guillaume
      
      
 2017 年 9 月 11 日
        If you want 4 columns, then your reshape is wrong. You probably meant:
Var1 = reshape(Mat(:, 1, :), [], 4);
%...
If I understood correctly you want a table with 5 rows, 10 variables, where each variable has 4 columns. reshape is the wrong tool for that. permute is the right tool.
mat = randi([0 20], 5, 10, 4);
splitmat = num2cell(permute(mat, [1 3 2]), [1 2]);  %move 3rd dimension as column, then split into cell array keeping rows and columns together
T = table(splitmat{:})
その他の回答 (0 件)
参考
カテゴリ
				Help Center および File Exchange で Tables についてさらに検索
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
