I want to convert Matlab to fortran
3 views (last 30 days)
Show older comments
this code is matlab but I want to change fortran
function Cart = sphcart( Sph, SphV )
if iscell(Sph)
Cart = { Sph{1}.*cos(Sph{2}).*cos(Sph{3}),...
Sph{1}.*cos(Sph{2}).*sin(Sph{3}),...
Sph{1}.*sin(Sph{2}) };
else
Cart = [ Sph(:,1).*cos(Sph(:,2)).*cos(Sph(:,3)),...
Sph(:,1).*cos(Sph(:,2)).*sin(Sph(:,3)),...
Sph(:,1).*sin(Sph(:,2)) ];
end
if nargin == 1, CartV = []; return; end
% Vector transformation
if iscell(Sph)
if ~iscell(SphV)
SphV = {reshape(SphV(:,1),size(Sph{1})),reshape(SphV(:,2),size(Sph{1})),...
reshape(SphV(:,3),size(Sph{1}))};
end
Cart = repmat({SphV{1}},1,3).*...
{cos(Sph{3}).*cos(Sph{2}),sin(Sph{3}).*cos(Sph{2}),sin(Sph{2})}+...
repmat({SphV{2}},1,3).*...
{-cos(Sph{3}).*sin(Sph{2}),-sin(Sph{3}).*sin(Sph{2}),cos(Sph{2})}+...
repmat({SphV{3}},1,3).*...
{-sin(Sph{3}),cos(Sph{3}),zeros(size(Sph{1}))};
else
Cart = repmat(SphV(:,1),1,3).*...
[cos(Sph(:,3)).*cos(Sph(:,2)),sin(Sph(:,3)).*cos(Sph(:,2)),sin(Sph(:,2))]+...
repmat(SphV(:,2),1,3).*...
[-cos(Sph(:,3)).*sin(Sph(:,2)),-sin(Sph(:,3)).*sin(Sph(:,2)),cos(Sph(:,2))]+...
repmat(SphV(:,3),1,3).*...
[-sin(Sph(:,3)),cos(Sph(:,3)),zeros(length(Sph(:,3)),1)];
end
0 Comments
Answers (0)
See Also
Categories
Find more on Fortran with MATLAB in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!