MATLAB Answers

Plot disappears when trying to interpolate

2 次查看(过去 30 天)
Good afternoon,
In the code below for some weird reason i cant figure out how to interpolate the color so it changes as it extends away from (0,0,0), could you possibly tell me how I would be able to fix this?
clc; clear; close all;
i = 1;
PStress = zeros(134343,3);
Yieldstr = 1000; %KPa
minValue = -4*Yieldstr;
maxValue = 4*Yieldstr;
fidelity = Yieldstr/8; %We can adjust this to make cleaner graphs, might just take longer to run
for sigx = minValue:fidelity:maxValue
for sigy = minValue:fidelity:maxValue
for sigz = minValue:fidelity:maxValue
%Reduced to sig1-3
VM = (1/(sqrt(2)) * sqrt((sigx-sigy).^2 + (sigy-sigz).^2 +(sigz-sigx).^2));
if VM < Yieldstr
if (sigx==sigy) && (sigy==sigz) && (sigz==sigx)
%stops code
else
PStress(i,1) = sigx;
PStress(i,2) = sigy;
PStress(i,3) = sigz;
i = i + 1;
end
end
end
end
end
Data = sqrt(sigx.^2+sigy.^2+sigz.^2);
colormap cool
shading interp
D = alphaShape(PStress,inf);
Warning: Duplicate data points have been detected and removed.
plot(D,"FaceColor","none","EdgeColor","interp");
Warning: Error creating or updating Patch
Error in value of property FaceVertexCData
Number of colors must equal number of vertices
If you remove the edge color part you will see the plot comes back to its original shape. The goal is to have something that looks like this,
Thanks for the time as always,
Kevin

采纳的回答

Adam Danz
Adam Danz 2021-9-15
编辑:Adam Danz 2021-9-15
Plotting an alphaShape creates a patch object. When set to interp, the EdgeColor property requires existing CData or FaceVertexData prior to setting EdgeColor (see documentation). From your description, the interpolation should be based on distance to (0,0,0) so I've set CData to the distance of each vertex from (0,0,0).
i = 1;
PStress = zeros(134343,3);
Yieldstr = 1000; %KPa
minValue = -4*Yieldstr;
maxValue = 4*Yieldstr;
fidelity = Yieldstr/8; %We can adjust this to make cleaner graphs, might just take longer to run
for sigx = minValue:fidelity:maxValue
for sigy = minValue:fidelity:maxValue
for sigz = minValue:fidelity:maxValue
%Reduced to sig1-3
VM = (1/(sqrt(2)) * sqrt((sigx-sigy).^2 + (sigy-sigz).^2 +(sigz-sigx).^2));
if VM < Yieldstr
if (sigx==sigy) && (sigy==sigz) && (sigz==sigx)
%stops code
else
PStress(i,1) = sigx;
PStress(i,2) = sigy;
PStress(i,3) = sigz;
i = i + 1;
end
end
end
end
end
Data = sqrt(sigx.^2+sigy.^2+sigz.^2);
colormap cool
shading interp
D = alphaShape(PStress,inf);
Warning: Duplicate data points have been detected and removed.
h = plot(D, 'FaceColor', 'none');
distance = sqrt(sum(h.Vertices,2).^2);
h.CData = distance;
h.EdgeColor = 'interp';
cb = colorbar();
ylabel(cb, 'Distance');
xline(0, 'k:')
yline(0, 'k:')
  1 个评论
Kevin Hanekom
Kevin Hanekom 2021-9-15
This is amazing, thank you for solving this for me! so much to learn, exciting.

请先登录,再进行评论。

更多回答(0 个)

Community Treasure Hunt

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

Start Hunting!

Translated by