How to compare elements of rows within cell array?
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hey All ... I have an array 'array1'. I want to compare each elements of array1 with other elements.
array1= {[1,2,3,8];[1,6];[1,2,3];[1,5,6];[2,4,5];[1,7];[2,8];[2,3,5,7,9]}
e.g. first elements is array1{1,1}={[1,2,3,8]}
All these values 1,2,3,8 will be compared with all other elements of array1 one by one. And find out where that value is present in other elements of array1, index of that row will be saved in resultant array.
ResultantArray{1,1} = {[2,3,4,6];[3,5,7,8];[3,8];[7]} % e.g. [2,3,4,6] is result of comparing '1' with others and 2,3,4,6 are rows where 1 is present in array1.
ResultantArray{2,1} = {[1,3,4,6];[4]} % similary [1,6] are compared with others and {[1,3,4,6];[4]} are rows where these are present.
ResultantArray{3,1} = {[1,2,4,6];[1,5,7,8];[1,8]}
and so on for other elements of array1.
please help.
0 commentaires
Réponse acceptée
Birdman
le 10 Jan 2018
for k=1:size(array1,1)
for j=1:numel(array1{k,1})
for i=1:size(array1,1)
[~,idx(i,j,k)]=ismember(array1{k,1}(j),array1{i,1});
end
ResultantArray{k,j}=setdiff(find(idx(:,j,k)),k);
end
end
Plus de réponses (1)
Voir également
Catégories
En savoir plus sur Matrices and Arrays dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!