## Switching scales on x axis

Hans123

### Hans123 (view profile)

님이 질문을 제출함. 13 Mar 2019
최근 활동 Star Strider

### Star Strider (view profile)

님이 댓글을 추가함. 13 Mar 2019
Star Strider

### Star Strider (view profile)

님이 답변을 채택함.
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;

로그인 to comment.

R2017b

## 답변 수: 1

Star Strider

### Star Strider (view profile)

님의 답변 13 Mar 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))

Hans123

### Hans123 (view profile)

13 Mar 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 (view profile)

13 Mar 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.

로그인 to comment.