็็Have a question about plot graph
1 次查看(过去 30 天)
显示 更早的评论
I'm new to Matlab program, I want to plot mesh 3D graph but this code have a problem in "mesh(T,Cs,x)" please give any advise to me.
Thank you
%Graph 1
T=[873:100:1073];
Cs=[0.15 0.30 0.45];
[T,Cs]=meshgrid(T,Cs);
mesh(T,Cs,x)
Ylabel('length Carbon can diffuse(cm)','fontsize',18);
Xlabel('temperature (°C)','fontsize',18);
Zlabel('CarbonStart ,fontsize',18);
3 个评论
Walter Roberson
2021-12-20
Cs=[15 30 45];%%Carbon at surface
Vector.
Cx=0.12;
C0= 0.08;%Carbon in specimen
scalar and scalar
Erf = (Cs-Cx)./(Cs-C0);
vector minus scalar is vector, vector minus scalar is vector, vector ./ vector with the same orientation gives a vector result, so Erf is a vector.
z=NaN(size(Erf));
So z will be initialized as a vector.
for n = 1 : numel(Erf)
if Erf(n)<2
z(n)=(-0.3725*Erf(n)^2)+(1.2144*(Erf(n)))+(0.0006);%error(0.01-0.08%) 0.4286
else
z(n)=(-0.0109*Erf(n)^2)+(0.0577*(Erf(n)))+(0.9235);%error(<0.01%)
end
%find X6
Scalar entries of z are assigned to, so z remains a vector.
x = z .* scalingFactor; %%% ***t=3600***
all of x is being overwritten each time. The right hand side uses all of z, including the entries that are still nan because they have not been written to yet, so x will be set as something the same size as z, so x will be a vector.
T=[873:100:1073];
Cs=[0.15 0.30 0.45];
[T,Cs]=meshgrid(T,Cs);
After that, T and Cs will be 2D grids that are 3 x 3.
mesh(T,Cs,x)
T is 3x3, Cs is 3x3, x is a vector the same size as z which is the same size as Erf which is the same size as the earlier meaning of Cs.
Note by the way that the earlier Cs uses 15, 30, 45, but the new Cs uses 0.15, 0.30, 0.45, which is 100 times smaller. Using that as coordinates for a plot is misleading, as the calculation was done in terms of the larger-scale Cs.
You are plotting x as if it depends upon T (temperature), but nothing in your calculation uses temperature.
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Surface and Mesh Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!