How to set the step size in z axis?

1 vue (au cours des 30 derniers jours)
adi kul
adi kul le 8 Juin 2016
Modifié(e) : dpb le 8 Juin 2016
Hello All, I am having a bit difficulty in setting the step size of the graph.
Currently on Z axis I am plotting pressure which is calculated from lot of things. So my current code is:
zlabel('pressure (MPa)')
colorbar
Now by default the Z axis is equally divided with 100 MPa steps which I want to increase it to 200 MPa steps. The issue is for every calculation the max of pressure changes so does the graph and hence I can not add zlim[ ] in it. But still I want only change the step size.
Can anyone help me?

Réponses (1)

dpb
dpb le 8 Juin 2016
Modifié(e) : dpb le 8 Juin 2016
To keep the autoranging limits if they're ok and using a tick spacing of 100, but you want 200, simply
ztk=get(gca,'ztick'); % retrieve current tick locations
set(gca,'ztick',ztk(1z1:2:end)) % setting new ticks at half spacing
If you need to readjust the start value, you'll have to query the min/max from each data set and determine a suitable zlim range and ztick spacing but sounds as though you're ok with the auto range, just want to change the number of ticks...above will reduce by a factor of two beginning with the first; if it were an odd value and you wanted the evens, you'd have to check the value of the first element in ztk and see if want to start with ztk(1) or ztk(2), that is
iz1=mod(ztk(1),200)==100+1; % first index in default ztick divisible by 200
Demo: try
surf(20*peaks(50))
ztk=get(gca,'ztick');
iz1=mod(ztk(1),200)+1;
pause(2) % delay to see initial plot before
set(gca,'ztick',ztk(1:2:end)) % reset z tick spacing

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by