x,y,z values in 3d plot
1 view (last 30 days)
Show older comments
Francesco Marchione
on 20 Nov 2021
Commented: Star Strider
on 20 Nov 2021
Could you please help me in getting a 3d plot showing the extreme coordinates for x, y?
I want also to indicate the preferred interval for z values.
I attach the Star's code I used and the correct excel file.
Thanks !
T1 = readtable('URM_shear_EPX1.xlsx', 'VariableNamingRule','preserve');
% First10Rows = T1(1:10,:)
% T1Sz = size(T1)
VarNames = T1.Properties.VariableNames;
N = 50; % Interpolation Matrix Size
xv = linspace(min(T1{:,1}), max(T1{:,1}), N); % Create Vector
yv = linspace(min(T1{:,2}), max(T1{:,2}), N); % Create Vector
[Xm,Ym] = ndgrid(xv,yv); % Create Interpolation Matrices
Zm = griddata(T1{:,1}, T1{:,2}, T1{:,3}, Xm, Ym); % Interpolate
figure
surfc(Xm, Ym, Zm)
grid on
shading interp
set(0, 'DefaultTextInterpreter', 'latex')
hcb = colorbar;
xlabel(hcb,'[{\it Pa}]');
hcb.Label.Interpreter = 'latex';
set(hcb,'TickLabelInterpreter','latex')
colormap(jet(50))
title ('EPX1','FontSize',11,'interpreter', 'latex')
set(0, 'DefaultTextInterpreter', 'latex')
hcb = colorbar;
hcb.TickLabelInterpreter='latex';
ColorbarRulerProperties = hcb.Ruler
hcb.Ruler.TickLabelFormat = '%.2f';
% set(hcb, 'Ticks', sort([hcb.Limits, hcb.Ticks]))
%%%%%%%%%%%%
Nticks = 10; % define number of ticks displayed in colorbar
aa = hcb.Limits;
CBAR_ticks = linspace(aa(1),aa(2),Nticks);
set(hcb, 'Ticks', CBAR_ticks);
%%%%%%%%%%%%
set(gca,'TickLabelInterpreter','latex')
% tix = hcb.Ticks;
% expstr = @(x) [x(:).*10.^ceil(-log10(abs(x(:)+(x==0)))) floor(log10(abs(x(:)+(x==0))))];
% tixexp = expstr(tix(:))
% tixexplbl = compose('%.2f \\times 10^{%2d}',[tixexp(:,1) fix(tixexp(:,2))])
% hcb.TickLabels = tixexplbl;
xlabel('{\it x} [{\it mm}]')
ylabel('{\it y} [{\it mm}]')
zlabel('{\it} Shear stress [{MPa}]')
3 Comments
Walter Roberson
on 20 Nov 2021
I was concerned about your duplicate data warning
filename = 'https://www.mathworks.com/matlabcentral/answers/uploaded_files/807734/URM_shear_EPX1.xlsx';
T1 = readtable(filename, 'VariableNamingRule','preserve');
x = T1{:,1}; y = T1{:,2}; z = T1{:,3};
xy = [x,y];
size(xy)
[uxy, ia, ~] = unique(xy, 'rows');
size(uxy)
ux = x(ia); uy = y(ia); uz = z(ia);
subplot(2,1,1);
scatter3(x, y, z);
xlabel('x'); ylabel('y'); zlabel('z');
title('full data');
subplot(2,1,2);
scatter3(ux, uy, uz);
xlabel('x'); ylabel('y'); zlabel('z');
title('first unique data');
uxyz = unique([x, y, z], 'rows');
size(ux)
size(uxyz)
So it turns out that you have a lot of duplicated data points (more than 2/3 are duplicates.) But it also turns out that they are complete duplicates in each case: in every case where a particular x, y pair is duplicated, the z have exactly the same value.
This tells us that you should probably pull out the components of uxyz to use in the data gridding, just to be cleaner, but that in this particular case it will not make a difference.
In most cases where you see that warning message, it indicates that you have two different z values associated with the same grid point, and that can spoil meaningful interpolation.
Accepted Answer
Star Strider
on 20 Nov 2021
Perhaps this —
T1 = readtable('https://www.mathworks.com/matlabcentral/answers/uploaded_files/807724/URM_shear_EPX1.xlsx', 'VariableNamingRule','preserve');
Extremes = varfun(@(x)[min(x); max(x)], T1);
Extremes.Properties.RowNames = {'Minimum','Maximum'}
% First10Rows = T1(1:10,:)
% T1Sz = size(T1)
VarNames = T1.Properties.VariableNames;
N = 50; % Interpolation Matrix Size
xv = linspace(min(T1{:,1}), max(T1{:,1}), N); % Create Vector
yv = linspace(min(T1{:,2}), max(T1{:,2}), N); % Create Vector
[Xm,Ym] = ndgrid(xv,yv); % Create Interpolation Matrices
Zm = griddata(T1{:,1}, T1{:,2}, T1{:,3}, Xm, Ym); % Interpolate
figure
surfc(Xm, Ym, Zm)
grid on
shading interp
set(0, 'DefaultTextInterpreter', 'latex')
hcb = colorbar;
xlabel(hcb,'[{\it Pa}]');
hcb.Label.Interpreter = 'latex';
set(hcb,'TickLabelInterpreter','latex')
colormap(turbo(50))
title ('EPX1','FontSize',13,'interpreter', 'latex')
set(0, 'DefaultTextInterpreter', 'latex')
hcb = colorbar;
hcb.TickLabelInterpreter='latex';
ColorbarRulerProperties = hcb.Ruler;
hcb.Ruler.TickLabelFormat = '%.2f';
% set(hcb, 'Ticks', sort([hcb.Limits, hcb.Ticks]))
%%%%%%%%%%%%
Nticks = 10; % define number of ticks displayed in colorbar
aa = hcb.Limits;
CBAR_ticks = linspace(aa(1),aa(2),Nticks);
set(hcb, 'Ticks', CBAR_ticks);
%%%%%%%%%%%%
set(gca,'TickLabelInterpreter','latex')
% tix = hcb.Ticks;
% expstr = @(x) [x(:).*10.^ceil(-log10(abs(x(:)+(x==0)))) floor(log10(abs(x(:)+(x==0))))];
% tixexp = expstr(tix(:))
% tixexplbl = compose('%.2f \\times 10^{%2d}',[tixexp(:,1) fix(tixexp(:,2))])
% hcb.TickLabels = tixexplbl;
xlabel('{\it x} [{\it mm}]')
ylabel('{\it y} [{\it mm}]')
zlabel('{\it} Shear stress [{MPa}]')
.
4 Comments
Star Strider
on 20 Nov 2021
My pleasure!
If my Answer helped you solve your problem, please Accept it!
.
More Answers (0)
See Also
Categories
Find more on Graphics Objects in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!