x,y,z values in 3d plot

조회 수: 10 (최근 30일)
Francesco Marchione
Francesco Marchione 2021년 11월 20일
댓글: Star Strider 2021년 11월 20일
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
Warning: Duplicate data points have been detected and removed - corresponding values have been averaged.
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
ColorbarRulerProperties =
NumericRuler with properties: Limits: [-0.6692 8.1822] Scale: 'linear' Exponent: 0 TickValues: [0 1 2 3 4 5 6 7 8] TickLabelFormat: '%g' Show all properties
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
Walter Roberson
Walter Roberson 2021년 11월 20일
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)
ans = 1×2
46208 2
[uxy, ia, ~] = unique(xy, 'rows');
size(uxy)
ans = 1×2
11781 2
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)
ans = 1×2
11781 1
size(uxyz)
ans = 1×2
11781 3
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.
Francesco Marchione
Francesco Marchione 2021년 11월 20일
I would like to see in the graph the x values from 0 to -25.40 mm (i.e., I would like to see these extreme values represented), and the y extreme values as well.
I would also like to decide the interval of z values to plot.

댓글을 달려면 로그인하십시오.

채택된 답변

Star Strider
Star Strider 2021년 11월 20일
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'}
Extremes = 2×3 table
Fun_X Coordinate (mm) Fun_Z Coordinate (mm) Fun_Shear Stress (MPa) _____________________ _____________________ ______________________ Minimum -12.533 -25.066 -0.68366 Maximum 0.167 0.334 8.5386
% 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
Warning: Duplicate data points have been detected and removed - corresponding values have been averaged.
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
Francesco Marchione
Francesco Marchione 2021년 11월 20일
Many thanks for your help. Francesco
Star Strider
Star Strider 2021년 11월 20일
My pleasure!
If my Answer helped you solve your problem, please Accept it!
.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Colormaps에 대해 자세히 알아보기

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by