I have two vectors A and B of the same size.I have the following code.
y1=[];y2=[];y3=[];y4=[];
for i=1:length(A)
for k=0:0.1:1
for m=0:0.1:1
h=k*m/(k+m-k*m);
if(h==A(i))
y1=[y1 k];
y2=[y2 m];
end
if(h==B(i))
y3=[y3 k];
y4=[y4 m];
end
end
end
end
This code runs fine. But in this code say for example if h=A(i)=0.2
is true. Then y1 and y2 can only take the combinations [0,0.2],[0.2,0]
If h=B(i)=0.4
is true then y3 and y4 can take combinations[0,0.04],[0.02,0.02],[0.01,0.03] likewise. I want to group all the combinations of B for a particular A(i) and to know when A(i) takes a different value, and for that different A(i) the corresponding B(j)'s.
So I wrote the following code.
y1=[];y2=[];y3=[];y4=[];
for i=1:length(A)
istrue=0;
for k=0:0.01:1
for m=0:0.01:1
h=k*m/(k+m-k*m);
if(h==A(i))
istrue=1;
y1=[y1 k];
y2=[y2 m];
end
if(istrue==1)
if(h==B(i))
y3=[y3 k];
y4=[y4 m];
end
end
istrue=0;
end
end
end
But the problem is this never executes the part
if(h==B(i))
y3=[y3 k];
y4=[y4 m];
end
If I remove istrue
variable and run as in the previous code it works.
if(h==A(i))
istrue=1;
y1=[y1 k];
y2=[y2 m];
end
gets executed at least once. Yet the part
if(h==B(i))
y3=[y3 k];
y4=[y4 m];
end `
doesn't get executed.
What is wrong with my code?Is the issue with the istrue
variable?
Aucun commentaire:
Enregistrer un commentaire