MATLAB Answers

I want to convert from Cartesian to spherical coordinates in MATLAB. I have tried to use cart2sph in MATLAB but it is showing some error

28 views (last 30 days)
Ahmad Bilal
Ahmad Bilal on 18 Mar 2018
Answered: SUDWEEP SARMA on 2 Jul 2020
My MATLAB Code is as follows :
function [phi,theta] = calc_phitheta_geom(xyz_source,xyz_mic1,xyz_mic2)
mid_p =(xyz_mic1 + xyz_mic2)/2 %midpoint calculation of xyz_mic1 and xyz_mic2
V = mid_p - xyz_source %Vector from midpoint till xyz_source
[phi,theta] = cart2sph(V) %converting Vector V from cartesian to spherical
end
Now actually Matlab command requires parameter for cart2sph as follows:
[phi,theta] = cart2sph(x,y,z) % here x y z are cartesian coordinates.
My question is that when I am using [phi,theta] = cart2sph(V) it is showing not enough input arguments.
How can I resolve this issue? Can anybody help me in this regard?
Thank you.

  0 Comments

Sign in to comment.

Accepted Answer

Ahmet Cecen
Ahmet Cecen on 18 Mar 2018
You have to actually input the x, y and z vectors separately.Like
[azimuth,elevation,r] = cart2sph(V(:,1),V(:,2),V(:,3));

  0 Comments

Sign in to comment.


Translated by