can this loop be vectorized
Afficher commentaires plus anciens
Can this loop be vectorized?
a=[5,7,8,5,6];
n=length(a);
b=a;
c=zeros(n,n);
for i=1:length(a)
for j=1:length(a)
if a(i)==b(j)
c(i,j)=0;
end
if a(i)~=b(j)
c(i,j)=1;
end
end
end
c
It returns
0 1 1 0 1
1 0 1 1 1
1 1 0 1 1
0 1 1 0 1
1 1 1 1 0
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Agriculture dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!