Same Y-axis but two X-axis

12 visualizaciones (últimos 30 días)
Pouyan Msgn
Pouyan Msgn el 20 de Sept. de 2020
Editada: Ameer Hamza el 20 de Sept. de 2020
Hi ! I wish to have this code with two X-axis...
clc
clear all
x=-4:0.1:4;
y=sin(2*x);
plot(x,y)
grid on
figure
x2=-0.4:0.01:0.4;
y2=sin(20*x2);
plot(x2,y2)
grid on
I searched about it and found some topics but it was not easy. How can I have two X-axis ?

Respuestas (1)

Ameer Hamza
Ameer Hamza el 20 de Sept. de 2020
Editada: Ameer Hamza el 20 de Sept. de 2020
Try this
x1 = -4:0.1:4;
y1 = sin(2*x1);
x2 = -0.4:0.01:0.4;
y2 = sin(20*x2);
f = figure();
ax1 = axes();
hold(ax1);
grid on
ax1.XLim = [-4 4];
ax1.YLim = [-1.5 1.5];
plot(x1, y1, 'r')
ax2 = axes('Position', ax1.Position);
hold(ax2);
ax2.Position = ax1.Position;
ax2.Color = 'none';
ax2.XAxis.Visible = 'off';
ax2.YAxis.Visible = 'off';
ax2.XLim = [-4 4];
ax2.YLim = [-1.5 1.5];
plot(x2, y2, 'b')

Categorías

Más información sobre Colormaps en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by