hi, i want to do table group :
1 column :3,5,9,12
2 column: 4,6,7,8,10,11
3 colum (no..because this element are identical at colum 1 )
..
the column with all zero element to be not insert! (and the column egual )
finally i get this matrix (colum 5,6,7,8 are clone...i not insert it in the group)
1 column :3,5,9,12,0,0
2 column: 4,6,7,8,10,11
i try to use world reserved "unique" but i can't do it

 채택된 답변

Voss
Voss 2023년 8월 7일
편집: Voss 2023년 8월 7일

1 개 추천

M = [0 0 3 4 3 4 4 4; 0 0 5 6 5 6 6 6; 0 0 9 7 9 7 7 7; 0 0 12 8 12 8 8 8; 0 0 0 10 0 10 10 10; 0 0 0 11 0 11 11 11; 0 0 0 0 0 0 0 0; 0 0 0 0 0 0 0 0; 0 0 0 0 0 0 0 0]
M = 9×8
0 0 3 4 3 4 4 4 0 0 5 6 5 6 6 6 0 0 9 7 9 7 7 7 0 0 12 8 12 8 8 8 0 0 0 10 0 10 10 10 0 0 0 11 0 11 11 11 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
% unique() by column:
M = unique(M.','rows','stable').'
M = 9×3
0 3 4 0 5 6 0 9 7 0 12 8 0 0 10 0 0 11 0 0 0 0 0 0 0 0 0
% remove all-0 rows:
M(all(M == 0,2),:) = [];
% remove all-0 columns:
M(:,all(M == 0,1)) = [];
disp(M);
3 4 5 6 9 7 12 8 0 10 0 11

댓글 수: 4

pipin
pipin 2023년 8월 7일
편집: pipin 2023년 8월 7일
M = unique(M.','rows','stable').'
what is . after M? (M.)
i try to remove it and the result is the same
Voss
Voss 2023년 8월 7일
.' is transpose
' is complex conjugate transpose
By removing the . you went from using tranpose to complex conjugate transpose, which means that the code will not work as intended for complex-valued matrices. But since your matrix is real-valued its complex conjugate is itself so the result is the same whether you use .' or ' in this case.
pipin
pipin 2023년 8월 7일
thank you for explenation
Voss
Voss 2023년 8월 7일
You're welcome!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터 및 File Exchange에서 MATLAB에 대해 자세히 알아보기

질문:

2023년 8월 7일

댓글:

2023년 8월 7일

Community Treasure Hunt

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

Start Hunting!

Translated by