how to reshape 2D to 3D in loop, when submatrix has different size
Show older comments
% example matrix
A =[1,1,2
1,5,2];
B =[2,2,4
2,4,7];
C =[3,2,4
3,4,7];
D =[4,2,4
4,2,4
4,4,7];
Input=[A;B;C;D];
%Extract the submatrix and defined as X(i).This based on their common ID=i [m,d]=size(Input);
ID.uni=unique(Input(:,1)); % unique all the ID: 01,02...k
k=length(ID.uni);
X=[];
for i=1:k
rows_i= find(Input(:,1)==ID.uni(i)); % index which rows have the same ID
X(:,:,i)=Input([rows_i],:);
end
Answers (0)
Categories
Find more on Creating and Concatenating Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!