Borrar filtros
Borrar filtros

Info

La pregunta está cerrada. Vuélvala a abrir para editarla o responderla.

Where did i mess those "for-loops" up?

1 visualización (últimos 30 días)
andreas
andreas el 17 de Jul. de 2013
Cerrada: MATLAB Answer Bot el 20 de Ag. de 2021
" matrixg" is a 3d array, which contains incidence matrices of Graphs with 7 edges. This program should eliminate all Graphs which have a circle with 3 vertices.
I included a counter "g" and because of it, i think he realizes isomorphy as often as i think it should (19) times. Unfortunately the 3d-matrix H at then end still has size 33.
I think i either closed on "for" too early. But somehow i can't fix it myself.
clc
D=sparse([1 1 2],[2 3 3],true,3,3);
load('matrixg.mat')
c=[0 0 0 0 0 0 0];
a=1;
g=0;
[~, ~, z]=size(G);
for l=1:z
zaehler=0;
for i=1:7
%T1=[G(:,:,l) ; c];
T1=sparse(G(:,:,l));
T1(:,i)=[];
T1(i,:)=[];
for k=1:6
T2=T1;
T2(:,k)=[];
T2(k,:)=[];
for l=1:5
T3=T2;
T3(:,l)=[];
T3(l,:)=[];
for m=1:4
T=T3;
T(:,m)=[];
T(m,:)=[];
[F1] = graphisomorphism(T+T',D+D','directed', false);
if F1==1
zaehler=1;
g=g+1;
end
end
if zaehler==1
break
end
end
if zaehler==1
break
end
end
if zaehler==1
break
end
end
if zaehler==0
H(:,:,a)=G(:,:,l);
%view(biograph(H(:,:,a)));
a=a+1;
end
end
  1 comentario
dpb
dpb el 18 de Jul. de 2013
a=1;
g=0;
for l=1:z
zaehler=0;
for i=1:7
...
for k=1:6
...
for l=1:5
...
for m=1:4
....
[F1] = graphisomorphism(T+T',D+D','directed', false);
if F1==1
zaehler=1;
g=g+1;
break % LOOKS TO ME LIKELY NEED THIS....
end
end
if zaehler==1, break, end
end
if zaehler==1, break, end
end
if zaehler==1, break, end
end
if zaehler==0
H(:,:,a)=G(:,:,l);
a=a+1;
end
end
I recast your code a little including indenting uniformly and replacing the multi-line 'break' clauses w/ single to make flow easier to follow (imo such are better w/o the additional nesting).
It appears to me you likely need the additional break when first find the case in the innermost loop.
Otherwise, set up a dataset that has only a couple cases and use the debugger to step through and see where it isn't branching as you think should...

Respuestas (0)

La pregunta está cerrada.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by