Switching scales on x axis

1 次查看(过去 30 天)
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;

采纳的回答

Star Strider
Star Strider 2019-3-13
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 个评论
Hans123
Hans123 2019-3-13
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 2019-3-13
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.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 2-D and 3-D Plots 的更多信息

产品


版本

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by