I am mistaken for angle
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Muhendisleksi
el 2 de Mzo. de 2017
Comentada: Muhendisleksi
el 2 de Mzo. de 2017
Dx=[451.1489;71.922;22.064;-52.849;-434.247] Dy=[423.253;290.384;292.965; 296.519;377.443]
[u m]=size(Dx);
for i=1:u t(i)=atan(Dy(i)/Dx(i))*200/pi; end
if Dx(i)>0 & Dy(i)>0 t(i)=t(i) elseif Dx(i)<0 & Dy(i)>0 t(i)=t(i)+200 elseif Dx(i)<0 & Dy(i)<0 t(i)=t(i)+200; elseif Dx(i)>0 & Dy(i)<0 t(i)=t(i)+400; end
The result is wrong; t= [47.970; 84.543; 95.214; -88.771; 154.448]
The correct result is; t= [47.970; 84.543; 95.214; 111.229; 154.448]
Is line 4 causing the error?
0 comentarios
Respuesta aceptada
Jan
el 2 de Mzo. de 2017
Editada: Jan
el 2 de Mzo. de 2017
Note that you change the result outside the loop:
for i=1:u
t(i)=atan(Dy(i)/Dx(i))*200/pi;
end % <-- remove this
if Dx(i)>0 & Dy(i)>0
t(i)=t(i) % Omit this one :-)
elseif Dx(i)<0 & Dy(i)>0
t(i)=t(i)+200
elseif Dx(i)<0 & Dy(i)<0
t(i)=t(i)+200;
elseif Dx(i)>0 & Dy(i)<0
t(i)=t(i)+400;
end
% end % <-- insert an "end" here
When processed after the loop, only the last value of "i" is accessed.
Logical indexing will be more efficient:
t = atan(Dy ./ Dx) * (200/pi); % elementwise: ./
index = (Dx<0 & Dy>0);
t(index) = t(index) + 200;
and so on.
Más respuestas (0)
Ver también
Categorías
Más información sobre GPU Computing in MATLAB 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!