I need to plot two x-axes with the same y-axis.
The first are the dates of a Satellite mission, the second one represents the distance.
I made the dates already as a string with the function "dates". So i just need to know what i have to add to:
h = figure
plot (dates,R_plot(:,1),'-','MarkerSize',6,'Color',colorset(5))
ylim([0 10000])
title ('Data rate over distance');
xlabel ('Distances in AU');
ylabel ('consequential data rate in bit/s');
I've been googling already the function "line" to just create another line, but it wasn't working out with a datestring for me.
I use Matlab2016b and i am quite new.

1 件のコメント

S. Gokhun Tanyer
S. Gokhun Tanyer 2022 年 12 月 27 日
I was searching for the same exact thing.
It is too bad there are no solutions listed here. :(

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

 採用された回答

dpb
dpb 2017 年 7 月 15 日
編集済み: dpb 2022 年 12 月 27 日

0 投票

See <graph-with-multiple-x-axes> for example. They've really made it hard to find the link; I never did find it in current doc; had to look it up in R2014b where I knew it existed to find the phrase and then do a text search... :( And, since they built yyaxis in lieu of old plotyy, why wouldn't they have gone ahead and introduced xxaxis as well? Makes no sense what TMW does/doesn't do sometimes...
"made dates already as a string with the function "dates" " I don't find any function dates; do you mean datestr, perhaps? If so, you want to plot using a datetime value and format it as desired, not a string.

3 件のコメント

dpb
dpb 2017 年 7 月 15 日
[Moved Nikolai's Answer to Comment...dpb]
You are right! I was using "datetime". I already found the same page you have been sending. But i still don't know how to change the second x-Axis to a datetime Value.
My Solution right now is to first plot the dates and afterwards the distances:
h = figure
plot (dates,R_plot(:,1),'-','MarkerSize',6,'Color',colorset(5))
ylim([0 10000])
xlabel ('Distances in AU');
ylabel ('consequential data rate in bit/s');
ax1 = gca;
ax1_pos = ax1.Position;
ax2 = axes('Position',ax1_pos,...
'XAxisLocation','top',...
'YAxisLocation','right',...
'Color','none');
%Eliminating second y-Axis
set(gca,'ytick',[])
% With AU_ent as the distances in AU
x2 = AU_ent;
%Random value
y2 = 0;
line(x2,y2,'Parent',ax2,'Color','k')
Even i did not find the perfect solution, Many thanks for your help!
dpb
dpb 2017 年 7 月 15 日
I'm still not positive what it is you're wanting here, Nikolai (which is why I didn't try specific code first go 'round; wasn't sure what code to give :) ).
To set the second axis in time units you need to set the x-axis limits in terms of time values and plot the data in those units as well. Can you attach some sample of what the resulting graph you're after would look like; even a sketch by hand would suffice, probably.
BTW, if you want two axes to be the same and stay in synch with each other, look at
doc linkaxes
for way to get that behavior.
dpb
dpb 2018 年 3 月 9 日
"what if I have data points and I don't want to have a line. Plot does not seem to work" -- Maxime Penning -- Answer moved to comment by dpb
Use the optional syntax to specify linestyle without a line type.
plot(x,y,'g.')
plots with green dots. doc plot for the details in the fine print on arguments.

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeTime Series Objects についてさらに検索

タグ

タグが未入力です。

質問済み:

2017 年 7 月 14 日

編集済み:

dpb
2022 年 12 月 27 日

Community Treasure Hunt

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

Start Hunting!

Translated by