Switching scales on x axis
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
Hans123
il 13 Mar 2019
Commentato: Star Strider
il 13 Mar 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;
0 Commenti
Risposta accettata
Star Strider
il 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))
2 Commenti
Star Strider
il 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.
Più risposte (0)
Vedere anche
Categorie
Scopri di più su 2-D and 3-D Plots in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!