3D surface plot from for loop

1 回表示 (過去 30 日間)
MATLABmet
MATLABmet 2017 年 1 月 26 日
コメント済み: John BG 2017 年 1 月 27 日
Hi all,
The following is my code, which calculates RF path loss between a satellite and a ground station, factoring in altitude and trajectory.
% code
f=5*10^6; %must be *10^3 less than given f. For example if f=5GHz, use 5MHz
h=700;
Gt=0;
Gr=0;
Nf=-100;
for i = 1:181
ang(i)=i-1
d(i)=sqrt(((6371+h)^2)-(6371^2)*(cos(ang(i)*(pi/180)).^2))-6371*sin(ang(i)*(pi/180));
Lp(i)=20*log10((4*pi()*d(i)*f)/(300000));
Pt=10*log10(57.27*0.193)+30; %convert to dbm
Pr(i)=Pt+Gt+Gr-Lp(i);
SNR(i)=Pr(i)-Nf
end
I can easily create 2D plots from this such as plot(ang,Lp) etc.. But I want to create a 3D plot using the surf command, which plots (ang,Lp,d).
How is this possible ?
Thanks in advance.
  1 件のコメント
John BG
John BG 2017 年 1 月 27 日
there are satellite comms examples readily available at the MATLAB file exchange.
For instance
available from
the channel is already modelled in some of the blocks.
John BG

サインインしてコメントする。

回答 (1 件)

Massimo Zanetti
Massimo Zanetti 2017 年 1 月 26 日
Most probably you don't want to plot a surface, instead a plot of a line in a 3D space. Try this:
plot3(ang,Lp,d); grid on;
Is that what you need?
  2 件のコメント
MATLABmet
MATLABmet 2017 年 1 月 26 日
Hi Massimo,
That looks more like what I want. However, I now want to bring the h value into the loop and make it range from 700:800Km. So really I need a 3 dimensional plot that represents distance, angle, and pathloss.
thanks again,
Massimo Zanetti
Massimo Zanetti 2017 年 1 月 26 日
編集済み: Massimo Zanetti 2017 年 1 月 26 日
Ok, so what you need is more likely a family of curves. Consider that there is no need of any loop, thanks to Matlab implicit expansion. See here:
f=5*10^6; %must be *10^3 less than given f. For example if f=5GHz, use 5MHz
Gt=0;
Gr=0;
Nf=-100;
h = (700:5:800)';
ang = 0:180;
d = sqrt(((6371+h).^2)-(6371^2)*(cos(ang*(pi/180)).^2))-6371*sin(ang*(pi/180));
Lp = 20*log10((4*pi*d*f)/(300000));
Pt = 10*log10(57.27*0.193)+30; %convert to dbm
Pr = Pt+Gt+Gr-Lp;
SNR =Pr-Nf;
plot3(ang,Lp,d); grid on;
If this answer helped you, please accept it.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeSurface and Mesh Plots についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by