Switching scales on x axis

조회 수: 1 (최근 30일)
Hans123
Hans123 2019년 3월 13일
댓글: Star Strider 2019년 3월 13일
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