How can I make x and y axis dates with contour?

53 ビュー (過去 30 日間)
Fatma Zehra Odabas
Fatma Zehra Odabas 2024 年 5 月 21 日
回答済み: Benjamin Kraus 2024 年 5 月 30 日
Hello,
I'm trying to make a Porkchop Plot for a journey from Earth to Mars. The purpose here is to plot the C3 values ​​that will coincide with the date of departure from Earth and the date of arrival on Mars as a contour function. In other words, there should be departure dates from Earth on the x-axis and arrival dates on Mars on the y-axis, but the contour function does not accept input as datetime. How can I solve this problem?

採用された回答

the cyclist
the cyclist 2024 年 5 月 21 日
That limitation is a shame.
One awkward solution is to convert the datetime values to datenums (which are purely numeric), and then use the datetick function to format the tick labels. (These are both "not recommended" by MathWorks, but I am not sure if there is a better way.)
If you post your data, someone may be able to give some more specific advice.
  2 件のコメント
Fatma Zehra Odabas
Fatma Zehra Odabas 2024 年 5 月 22 日
The method you mentioned worked. Thank you very much for your help.
Peter Perkins
Peter Perkins 2024 年 5 月 29 日
Limitation noted, thanks t. cyclist.

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

その他の回答 (1 件)

Benjamin Kraus
Benjamin Kraus 2024 年 5 月 30 日
In addition to @the cyclist's solution, there is another approach that leverages the newer datetime rulers, but is still a bit of a hack.
The key is to:
  1. Leverage another command (that does support datetime) to configure the axes.
  2. Turn hold on to prevent the next command from resetting the axes.
  3. Leverage ruler2num to convert your datetime/duration values to numeric before calling contour.
Here is an example with some dummy data:
x = datetime+minutes(1:49);
y = datetime+minutes(1:49);
% Call plot to configure the axes for datetime data.
ax = axes;
p = plot(x,y);
delete(p)
% Turn on 'hold' so that the contour command doesn't reset the axes
hold on
% Use ruler2num to convert the data to numeric data.
xn = ruler2num(x, ax.XAxis);
yn = ruler2num(y, ax.YAxis);
% Call contour
contour(xn, yn, peaks)

カテゴリ

Help Center および File ExchangeGeographic Plots についてさらに検索

製品


リリース

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by