Plotting linked double x-axis for one y-axis

I want to add a second x-axis to a plot, where the second x-axis is linked to the first x-axis with an inverse relation (eg. freq and wavelength). Thus the spacing on the second x-axis is not constant.
for example:
figure
hold on
x1 = 0:0.1:40;
x2 = 1./x1;
y = sin(x1)./(x1+2);
plot(x1,y,'Color','r')
% second x-axis for x2 here
I found a related example here https://www.mathworks.com/help/matlab/creating_plots/graph-with-multiple-x-axes-and-y-axes.html but it doesn't work for a linked double x-axis with a single y-axis. Also it only works with line.

 Respuesta aceptada

Ameer Hamza
Ameer Hamza el 16 de Mayo de 2020
Editada: Ameer Hamza el 16 de Mayo de 2020

0 votos

In MATLAB, there is no direct way to link two axes with the inverse relationship. However, a while ago, I answered a similar question: https://www.mathworks.com/matlabcentral/answers/509899-plot-with-two-related-x-axes. It changes the labels of top axes such that they appear to be linked. You can adapt that example according to your requirement. If you have any confusion, you can ask in the comment.

3 comentarios

Mohammadamir Ghaderi
Mohammadamir Ghaderi el 17 de Mayo de 2020
Editada: Mohammadamir Ghaderi el 17 de Mayo de 2020
Thanks! Albeit I was hoping for an easier approach, but it works.
Ameer Hamza
Ameer Hamza el 17 de Mayo de 2020
I am glad to be of help.
Hopefully, they will add this feature in future releases.
Ivan Bondarenko
Ivan Bondarenko el 31 de Jul. de 2022
Matlab is such garbage

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Creating, Deleting, and Querying Graphics Objects en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 16 de Mayo de 2020

Comentada:

el 31 de Jul. de 2022

Community Treasure Hunt

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

Start Hunting!

Translated by