I want to compare two arrays and check that which value is missing in second array as compared to first one?
21 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Aqeel Awan
am 4 Jul. 2021
Kommentiert: Aqeel Awan
am 4 Jul. 2021
A=[ 0 1 1 ;
1 1 0 ];
target=[1 2 3 4];
[m,n]=size(A);
c1=0;cover1=[];sum_coord=[];sss=0;
for i=1:m
cc=0;t_coordinate=[];
for j=1:n
if A(i,j)==1
cc=cc+1;
t_coordinate(cc,:)=j;
sss=sss+1;
sum_coord(sss,:)=t_coordinate(cc,:);
end
end
display(t_coordinate)
end
sum_coord=sort(sum_coord);
sum_coord=unique(sum_coord);
display(sum_coord)
first array is "Target" and second is "sum_coord"....
0 Kommentare
Akzeptierte Antwort
Rik
am 4 Jul. 2021
Bearbeitet: Rik
am 4 Jul. 2021
You should avoid variable names like sum, as that will prevent you from using the sum function.
Your question sounds like you need the ismember function. However, it is unclear how your code relates to the question in the title.
3 Kommentare
Rik
am 4 Jul. 2021
Did you try to google the documentation for the ismember function?
A=[ 0 1 1 ;
1 1 0 ];
target=[1 2 3 4];
[m,n]=size(A);
c1=0;cover1=[];sum_coord=[];sss=0;
for i=1:m
cc=0;t_coordinate=[];
for j=1:n
if A(i,j)==1
cc=cc+1;
t_coordinate(cc,:)=j;
sss=sss+1;
sum_coord(sss,:)=t_coordinate(cc,:);
end
end
end
sum_coord=sort(sum_coord);
sum_coord=unique(sum_coord);
disp(sum_coord)
L=ismember(target,sum_coord);
ismissing=target( ~L );
disp(ismissing)
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Structures finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!