如何根据矩阵的某一列​值的不同将矩阵进行分​割并命名。

大家好,我现在有一个矩阵,已经按第一列和第二列的升序进行了排序,现在我想通过第一列数值大小的不同将矩阵分成单独的几个不同的矩阵,要怎么样才可以实现呢,例如:[45 2 3;45 3 3;45 4 8; 47 2 1;47 3 6;47 4 9;51 2 8;51 3 6;51 4 7]分成单独的[45 2 3;45 3 3;45 4 8],[47 2 1;47 3 6;47 4 9],[51 2 8;51 3 6 ;51 4 7]并把分出来的三个矩阵按45 47 51进行命名呢。谢谢大家

 채택된 답변

0 개 추천

仅供参考
A=[45 2 3;45 3 3;45 4 8;   
    47 2 1;47 3 6;47 4 9;   
    51 2 8;51 3 6;51 4 7];
index=unique(A(:,1));
for i=1:length(index)
    mid = find(A(:,1)==index(i));
    B = A(mid,:);
    eval(['m',num2str(index(i)),'=','B']);
end   

추가 답변 (0개)

카테고리

도움말 센터 및 File Exchange에서 Operating on Diagonal Matrices에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!