How to find differences of 2 matrices which contain other matrices as elements?
조회 수: 1 (최근 30일)
이전 댓글 표시
o1 = eye(3,3);
o6=[1 -1 0; 1 0 0; 0 0 1];
o3=[0 -1 0;1 -1 0 ;0 0 1];
o2=[-1 0 0 ;0 -1 0; 0 0 1];
o3m=[-1 1 0; -1 0 0 ; 0 0 1];
o6m=[0 1 0; -1 1 0 ; 0 0 1];
omxx=[0 -1 0;-1 0 0; 0 0 1];
omx=[-1 1 0; 0 1 0; 0 0 1];
omy=[1 0 0 ;1 -1 0 ;0 0 1];
omxmx=[0 1 0;1 0 0; 0 0 1];
omx2x=[1 -1 0; 0 -1 0; 0 0 1];
om2xx=[-1 0 0 ; -1 1 0; 0 0 1];
G={o1,o6,o3,o2,o3m,o6m,omxx,omx,omy,omxmx,omx2x,om2xx};
labelsG={"o1","o6","o3","o2","o3m","o6m","omxx","omx","omy","omxmx","omx2x","om2xx"};
H={o1,o2};
labelsH={"o1","o2"};
K=setdiff(G,H);
Here my code. I want to find differences of G and H as J=[o6,o3,o3m,o6m,omxx,omx,omy,omxmx,omx2x,om2xx]
But it's not working
댓글 수: 0
답변 (2개)
Jan
2020년 12월 15일
The main problem is the choice of the data representation. Using an indexed field would allow to call setdiff().
Data.o1 = eye(3,3);
Data.o6 = [1 -1 0; 1 0 0; 0 0 1];
Data.o3 = [0 -1 0;1 -1 0 ;0 0 1];
Data.o2 = [-1 0 0 ;0 -1 0; 0 0 1];
Data.o3m = [-1 1 0; -1 0 0 ; 0 0 1];
Data.o6m = [0 1 0; -1 1 0 ; 0 0 1];
Data.omxx = [0 -1 0;-1 0 0; 0 0 1];
Data.omx = [-1 1 0; 0 1 0; 0 0 1];
Data.omy = [1 0 0 ;1 -1 0 ;0 0 1];
Data.omxmx = [0 1 0;1 0 0; 0 0 1];
Data.omx2x = [1 -1 0; 0 -1 0; 0 0 1];
Data.om2xx = [-1 0 0 ; -1 1 0; 0 0 1];
G = {"o1","o6","o3","o2","o3m","o6m","omxx","omx","omy","omxmx","omx2x","om2xx"};
H = {"o1","o2"};
Now setdiff(G, H) get the difference directly. Afterwards you can use something like Data.(G{1}) to get the corresponding values.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Whos에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!