classifying matrix value based on its element
조회 수: 4 (최근 30일)
이전 댓글 표시
All,
I have the following nx3 matrix. My question is how to classify these matrix based on the value in column 3, i.e. I want to group them based on the value that has similar values in column 3.
Please note that I may have hundreds of matrix similar to this one. I have produced the following code
sig3 = data(:,3);
sig3sort=zeros(length(sig3),1);
for ii=2:length(sig3)
if sig3(ii-1)==sig3(ii)
sig3sort(ii) = nan;
else
sig3sort(ii) = sig3(ii);
end
end
sig3sort = sig3sort(~isnan(sig3sort))
and wondering if someone can make it more elegant?
201 5 5
306 20 5
301 40 5
317 60 5
320 80 5
305 100 5
231 10 10
300 20 10
328 40 10
359 60 10
353 80 10
355 100 10
430 20 20
529 40 20
551 60 20
554 80 20
560 100 20
532 120 20
575 140 20
590 160 20
601 180 20
582 200 20
605 40 40
620 60 40
700 80 40
733 100 40
720 120 40
723 140 40
731 160 40
781 180 40
755 200 40
747 60 60
811 80 60
821 100 60
835 120 60
859 140 60
860 160 60
861 180 60
861 180 60
821 200 60
889 80 80
954 100 80
962 120 80
992 140 80
1003 160 80
1026 180 80
1052 200 80
998 220 80
1005 240 80
956 100 100
975 120 100
1012 140 100
1067 160 100
1089 180 100
1155 200 100
1106 220 100
1098 312 100
댓글 수: 0
답변 (2개)
Aquatris
2018년 7월 18일
Is this what you are trying to achieve;
a = [201 5 5
306 20 5
301 40 5
317 60 5
320 80 5
305 100 5
231 10 10
300 20 10
328 40 10
359 60 10
353 80 10
355 100 10
430 20 20
529 40 20
551 60 20
554 80 20
560 100 20
532 120 20
575 140 20
590 160 20
601 180 20
582 200 20
605 40 40
620 60 40
700 80 40
733 100 40
720 120 40
723 140 40
731 160 40
781 180 40
755 200 40
747 60 60
811 80 60
821 100 60
835 120 60
859 140 60
860 160 60
861 180 60
861 180 60
821 200 60
889 80 80
954 100 80
962 120 80
992 140 80
1003 160 80
1026 180 80
1052 200 80
998 220 80
1005 240 80
956 100 100
975 120 100
1012 140 100
1067 160 100
1089 180 100
1155 200 100
1106 220 100
1098 312 100];
checks = unique(a(:,3));
for i = 1:length(checks)
ind{i} = find(a(:,3) == checks(i));
end
group1 = a(ind{1},:);
group2 = a(ind{2},:);
...
참고 항목
카테고리
Help Center 및 File Exchange에서 Multidimensional Arrays에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!