Switching scales on x axis

1 Ansicht (letzte 30 Tage)
Hans123
Hans123 am 13 Mär. 2019
Kommentiert: Star Strider am 13 Mär. 2019
I am trying to swap the numbers on the x axis, which represents a distance of the plates of a capactior. Basically the capacitance should increase as the distance decrease
Capacitance values (y-axis) = [10 20 30 40...800]
Current distance values (x-axis) = [1 2 3 5... 490]
Required Scale for x-axis = [490 489... 4 3 2 1 0] *The last value should be zero, because the plates would be touching
Also the distance should be scaled up by a factor of 3000 and 7*z (piezo steps in z direction)
This is the code I have so far, it gives me the correct values, however it makes my matrix dimensions very large and it messes with my plot
Let me know what is the problem with it
d=3000.*M + 7.*z;
for k=1:max(d)-1
N(max(d)-k,:)=k;
end
N(max(d))=0;
distance=N;

Akzeptierte Antwort

Star Strider
Star Strider am 13 Mär. 2019
See if:
set(gca, 'XDir','reverse')
does what you want. That will reverse the x-axis direction, and the data associated with it, so the x-axis coordinates and the x-values of the data remain the same.
Otherwise, try something like this if you only want to reverse the axis labels and not the axis values themselves:
figure
plot(1:100, rand(1,100))
xt = get(gca, 'XTick');
xtr = linspace(max(xt), min(xt), numel(xt));
set(gca, 'XTick',xt, 'XTickLabel',sprintfc('%.1f', xtr))
you can also use the compose function:
set(gca, 'XTick',xt, 'XTickLabel',compose('%.1f', xtr))
  2 Kommentare
Hans123
Hans123 am 13 Mär. 2019
set(gca, 'XDir','reverse')
works exactly how I want the graph to look like, however I just want to flip the data not the axes as well. Please let me know what to do.
Thanks
Star Strider
Star Strider am 13 Mär. 2019
If you want to flip the data and not flip the axes, one approach would be to do both:
figure
plot(1:100, rand(1,100)+exp((0:99)/50))
set(gca, 'XDir','reverse')
xt = get(gca, 'XTick');
xtr = linspace(max(xt), min(xt), numel(xt));
set(gca, 'XTick',xt, 'XTickLabel',sprintfc('%.1f', xtr))
This first reverses the x-axis, then re-defines the x-axis tick labels.
The end effect is what you describe as what you want.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu 2-D and 3-D Plots finden Sie in Help Center und File Exchange

Produkte


Version

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by