Cant see the line in my plot

조회 수: 3 (최근 30일)
vas mit
vas mit 2019년 9월 24일
댓글: darova 2019년 9월 24일
for H=200:100:36000 %For loop created for the Height of the satellite
Gc = 398000.5 %Gravitational Constant times Earth's Mass
Re = 6371 %Radius of Earth
V = sqrt(Gc/(Re+H)) %Formula for calculating the Satellite Speed
hold on %Allows to plot multiple times on the same graph
plot(H, V,'-b') %Plot the Height with respect the Speed
end
ylabel('Orbital Speed (Km/S)'), xlabel('Height (Km)') %Labels on each axis
grid on %Grid added for easier understanding of data
My code works but i dont get the plot line when i run this..

채택된 답변

Ruger28
Ruger28 2019년 9월 24일
편집: Ruger28 2019년 9월 24일
Don't use plot if you are trying to plot each H vs V value. Use Scatter
for H=200:100:36000
Height(H) = H;
Gc = 398000.5; %Gravitational Constant times Earth's Mass
Re = 6371; %Radius of Earth
V = sqrt(Gc/(Re+H)); %Formula for calculating the Satellite Speed
scatter(H, V);
hold on %Allows to plot multiple times on the same graph
%Plot the Height with respect the Speed
end
ylabel('Orbital Speed (Km/S)'), xlabel('Height (Km)') %Labels on each axis
grid on
A more effifient way, and the better answer is this:
clear all;
figure;
Gc = 398000.5;
Re = 6371;
cntr = 1;
for H=200:100:36000
V(cntr) = sqrt(Gc/(Re+H))
Height(cntr) = H;
cntr = cntr + 1;
end
plot(Height,V)
ylabel('Orbital Speed (Km/S)');
xlabel('Height (Km)');
grid on;
The problem in your script is that you are plotting a single point, rather than a set of x&y values. Scatter plots a single point better.
The second bit of code is most likely what you are looking for.
  댓글 수: 2
vas mit
vas mit 2019년 9월 24일
Thank you so much it works! Just started with Matlabs for my Thesis project and it can get tricky a lot.
darova
darova 2019년 9월 24일
Preallocate arrays!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Reference Applications에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by