To have the colorbar display both extremes (max and min) and a fixed number of intermediate values at regular intervals automatically, you can set the “Ticks” property of the “colorbar” to a vector of values that spans from the minimum to the maximum of the data range, divided into equal intervals. You can do this using the “linspace” function.
Read more about “linspace” here:
Here's how you can modify your existing code to achieve this:
T1 = readtable('SLJ20 PEEL.xlsx', 'VariableNamingRule','preserve');
VarNames = T1.Properties.VariableNames;
N = 50;
xv = linspace(min(T1{:,1}), max(T1{:,1}), N);
yv = linspace(min(T1{:,2}), max(T1{:,2}), N);
[Xm,Ym] = ndgrid(xv,yv);
Zm = griddata(T1{:,1}, T1{:,2}, T1{:,3}, Xm, Ym);
figure
surfc(Xm, Ym, Zm)
grid on
shading interp
set(0, 'DefaultTextInterpreter', 'latex')
% Colorbar settings
hcb = colorbar;
xlabel(hcb,'[{\it Pa}]');
hcb.Label.Interpreter = 'latex';
set(hcb,'TickLabelInterpreter','latex')
colormap(jet(50))
title ('EPX1','FontSize',13,'interpreter', 'latex')
set(0, 'DefaultTextInterpreter', 'latex')
hcb = colorbar;
hcb.TickLabelInterpreter='latex';
% Define the number of intervals for the colorbar
numIntervals = 5;
cmin = min(Zm(:));
cmax = max(Zm(:));
ticks = linspace(cmin, cmax, numIntervals+1);
hcb.Ticks = ticks;
hcb.TickLabels = arrayfun(@(v) sprintf('%.2f', v), ticks, 'UniformOutput', false);
set(gca,'TickLabelInterpreter','latex')
xlabel('{\it x} [{\it mm}]')
ylabel('{\it y} [{\it mm}]')
zlabel('{\it} Shear stress [{\it MPa}]')
Read more about “Ticks” and “colobar” here: