how do i use different parts of a variable for the same code?
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Feliciano Döring
el 9 de Mayo de 2018
Comentada: Feliciano Döring
el 9 de Mayo de 2018
I have this code in which i have to calculate the Gn variable shown below for two different iterations. In each iteration the value of D(a matrix) changes. My question is how do i make it that for the first iteration the variables dn,dtx,dty,dtz and d0n use only the four numbers of m0 as it is now but for the second iteration it uses the last four numbers of m0.
outd0 = cell(2,1);
outGt = cell(1,2);
for iter=1:2
m0=[0; 0; 0; 0; 0 ;0 ;0 ;0];
sG=stationGroups{iter};
n=length(sG);
rowVector=ones(1,n);
dt0=rowVector;
D=sG';
dn=sqrt((D(1,:)-m0(2)).^2+(D(2,:)-m0(3)).^2+(D(3,:)-m0(4)).^2);
dtx = -(D(1,:)-m0(2))./(v.*dn);
dty = -(D(2,:)-m0(3))./(v.*dn);
dtz = -(D(3,:)-m0(4))./(v.*dn);
Gn=[dt0; dtx; dty; dtz];
Gt=Gn';
outGt{iter} = Gt;
Gt1=cell2mat(outGt(1,1));
Gt2=cell2mat(outGt(1,2));
G=blkdiag(Gt1,Gt2);
d0n=(m0(1)+(vecnorm(repmat(m0(2:4),1,n)-D(:,1:n)))./v);
d0t=d0n';
outd0{iter} = d0t;
d01=cell2mat(outd0(1,1));
d02=cell2mat(outd0(2,1));
d0=[d01;d02];
end
0 comentarios
Respuesta aceptada
Image Analyst
el 9 de Mayo de 2018
Editada: Image Analyst
el 9 de Mayo de 2018
Use an if statement
if iter == 1
dn=sqrt((D(1,:)-m0(2)).^2+(D(2,:)-m0(3)).^2+(D(3,:)-m0(4)).^2);
dtx = -(D(1,:)-m0(2))./(v.*dn);
dty = -(D(2,:)-m0(3))./(v.*dn);
dtz = -(D(3,:)-m0(4))./(v.*dn);
else
dn=sqrt((D(1,:)-m0(6)).^2+(D(2,:)-m0(7)).^2+(D(3,:)-m0(8)).^2);
dtx = -(D(1,:)-m0(6))./(v.*dn);
dty = -(D(2,:)-m0(7))./(v.*dn);
dtz = -(D(3,:)-m0(8))./(v.*dn);
end
However note that you set m0 to all zeros on every iteration so I don't see why you're even wanting to use it.
Más respuestas (1)
Ver también
Categorías
Más información sobre Bounding Regions en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!