There are many errors I cannot spot in this script. Can someone help please
Show older comments
This is what I am working with and I absolutely cannot get it to work.
function [r,theta,phi] = EGA118_M2_Q3s (x,y,z)
%%
%% This function returns the spherical polar coordinates (r, theta, phi)
%% that correspond to the input Cartesian coordinates (x, y, z).
%% theta (azimuthal angle) and phi (polar angle) are expressed in degrees.
if nargin == 0
r = 0;
theta = atan2(y,x);
phi = 0;
elseif nargin == 1
r = x;
theta = atan2(y,x);
phi = 0;
elseif nargin == 2
r = sqrt(x^2+y^2);
theta = atan2(y,x);
phi = 0;
else
r = sqrt(x^2+y^2);
theta = atan2d(y,x);
phi = atan2(z,r);
end
end
1 Comment
BobH
on 11 Mar 2020
When nargin is 0, x and y are not provided, so what values are being used in the atan2?
Similarly for nargin of 1, what value is being used for y in the atan2?
Accepted Answer
More Answers (0)
Categories
Find more on Lengths and Angles in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!