# How to arrange the correct range in colorbar in MATLAB

3 views (last 30 days)
Torkan on 7 Apr 2022
Commented: Mathieu NOE on 8 Apr 2022
Hello,
I have a 3D surface curvefit in matlab. The issue is for Z column the range is outside of the data range. How can I give correct range? This are my data and this is my code and actually it gives me wrong plot maybe. Would you pelase check it? Also, I want to remove the data points from the plot, how to do that?
Or if you have any other way to plot I would ppreciate it
clear all
x1 = M.(1) ;
y1 = M.(2) ;
z1 = M.(3);
s = fit([x1 y1],z1,"poly23");
plot(s,[x1 y1],z1);
c = jet(20);
colormap(c);
xlabel('HR')
ylabel('L/D')
zlabel('Fc')
colorbar

Mathieu NOE on 7 Apr 2022
hello
as I don't have the toolbox for fit, I used instead the FEX submission (excellent) from John D'Errico :
you can simply comment the line with scatter3 plot if you don't want the points on the plot
no issue so far...
code :
clear all
x1 = M.(1) ;
y1 = M.(2) ;
z1 = M.(3);
s = polyfitn([x1(:) y1(:)], z1(:), 2); % File Exchange by John D'Errico : https://fr.mathworks.com/matlabcentral/fileexchange/34765-polyfitn
[xx,yy] = meshgrid(0:1:10, 0:10:400);
zz = polyvaln(s, [xx(:) yy(:)]);
zz = reshape(zz, size(xx));
% remove data outise range
ind = (zz>=max(z1));
zz(ind) = NaN;
% plot points and surface
figure('Renderer','opengl')
scatter3(x1, y1, z1,'o','filled'); % comment this line if you don't want the points
surface(xx, yy, zz, ...
'FaceColor','interp', 'EdgeColor','b', 'FaceAlpha',0.4)
AZ = -37.5;
EL = 30;
view(AZ,EL)
grid on;
colormap(jet);
xlabel('HR')
ylabel('L/D')
zlabel('Fc')
colorbar;
Mathieu NOE on 8 Apr 2022
FYI the code works too (at least on my side) with the new data file (mmm.xlsx)
surface of order 1 :
s = polyfitn([x1(:) y1(:)], z1(:), 1); %
surface of order 2 :
s = polyfitn([x1(:) y1(:)], z1(:), 2); %