Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Matlab plot in spherical coordinates

Status
Not open for further replies.

sadra

Newbie
Newbie level 3
Joined
Feb 26, 2018
Messages
4
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
23
I want to know how to plot for example 1 (unit sphere) in theta=-pi/2 :pi/2 & phi=0:2×pi
Tnx
 

I want to know how to plot for example 1 (unit sphere) in theta=-pi/2 :pi/2 & phi=0:2×pi
Tnx

This may sound like a joke, but it really is as simple as this:


Code Matlab M - [expand]
1
sphere



If you click on the code, it will take you to the reference page for Matlab's sphere function.
 

If that doesn't give the insight you want, then you could write some code at a lower level. For example:


Code Matlab M - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
close all; clear all; clc;
 
% Numbers of azimuth and elevation points
Ntheta = 100;
Nphi = 100;
 
% Azimuth and elevation grids
theta = linspace(0,2*pi,Ntheta);
phi = linspace(-pi/2,pi/2,Nphi);
 
% Compute (x,y,z) coordinates
x = zeros(Ntheta,Nphi);
y = zeros(Ntheta,Nphi);
z = zeros(Ntheta,Nphi);
for itheta = 1:Ntheta
    for iphi = 1:Nphi
        x(itheta,iphi) = cos(theta(itheta)).*cos(phi(iphi));
        y(itheta,iphi) = sin(theta(itheta)).*cos(phi(iphi));
        z(itheta,iphi) = sin(phi(iphi));
    end
end
 
% Plot
figure(); grid on;
surf(x,y,z);
shading interp;
axis equal;

 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top