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

3 vues (au cours des 30 derniers jours)
极速百家乐网址【微8785092】
大家好,我现在有一个矩阵,已经按第一列和第二列的升序进行了排序,现在我想通过第一列数值大小的不同将矩阵分成单独的几个不同的矩阵,要怎么样才可以实现呢,例如:[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进行命名呢。谢谢大家

Réponse acceptée

百家乐真人网址网站【微8785092】
仅供参考
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   

Plus de réponses (0)

Catégories

En savoir plus sur 运算符和基本运算 dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!