How to mark points at 1-5 on the x-axis in the plot

2 次查看(过去 30 天)
clc;
clear all ;
Ld=(0:0.00005:0.005);
w=0.001;
L=0.007;
P=4*0.001;
Ta=25;
h=375;
Kf=175;
Kd=0.032;
Tb=75;
Ap=3.02*10^-3;
N=238;
Ac=10^-6;
m=92.6;
Lf=L-Ld;
Rtf=(cosh(m.*Lf)+(h./(m.*Kf)).*sinh(m.*Lf))./(sqrt(4*h.*(w)^3*Kf).*(sinh(m.*Lf)+h./(m.*Kf)).*cosh(m.*Lf));
R_fins=Rtf/N;
Rf_cond=Ld/(Kf*N*Ac);
Rd_cond=Ld/(Kd*(Ap-N*Ac));
Ad=Ld./(Kd*Rd_cond);
R_conv=1./(h*Ad);
q=(Tb-Ta)./(Rd_cond+R_conv)+(Tb-Ta)./(Rf_cond+R_fins);
Q=min(q);
figure
plot(Ld, q);
xlabel('Dust layer thickness, Ld (m)');
ylabel('Heat Rate, q(W)');
grid on;
fprintf("Total heat rate %.2f°C\n", Q);
  2 个评论
Dyuman Joshi
Dyuman Joshi 2023-10-13
编辑:Dyuman Joshi 2023-10-13
What do you mean by "mark points at 1-5 on the x-axis in the plot"?
Could you give an example of what the expected output is?

请先登录,再进行评论。

采纳的回答

Star Strider
Star Strider 2023-10-13
编辑:Star Strider 2023-10-13
One possibility —
clc;
clear all ;
Ld=(0:0.00005:0.005);
w=0.001;
L=0.007;
P=4*0.001;
Ta=25;
h=375;
Kf=175;
Kd=0.032;
Tb=75;
Ap=3.02*10^-3;
N=238;
Ac=10^-6;
m=92.6;
Lf=L-Ld;
Rtf=(cosh(m.*Lf)+(h./(m.*Kf)).*sinh(m.*Lf))./(sqrt(4*h.*(w)^3*Kf).*(sinh(m.*Lf)+h./(m.*Kf)).*cosh(m.*Lf));
R_fins=Rtf/N;
Rf_cond=Ld/(Kf*N*Ac);
Rd_cond=Ld/(Kd*(Ap-N*Ac));
Ad=Ld./(Kd*Rd_cond);
R_conv=1./(h*Ad);
q=(Tb-Ta)./(Rd_cond+R_conv)+(Tb-Ta)./(Rf_cond+R_fins);
Q=min(q);
figure
plot(Ld, q);
xlabel('Dust layer thickness, Ld (m)');
ylabel('Heat Rate, q(W)');
grid on;
fprintf("Total heat rate %.2f°C\n", Q);
Total heat rate 37.54°C
xlim([0 6]*1E-3)
Ldq = get(gca,'XTick');
qv = interp1(Ld, q, Ldq);
idx = isfinite(qv);
text(Ldq(idx), qv(idx), compose('Ld = %.3f\nq = %8.3f\n\\downarrow',[Ldq(idx); qv(idx)]'), 'Horiz','left', 'Vert','bottom', 'FontSize',8)
.

更多回答(1 个)

Dyuman Joshi
Dyuman Joshi 2023-10-13
编辑:Dyuman Joshi 2023-10-13
Okay, you want to create data-tips. Data-tips can be added using datatip -
Ld=(0:0.00005:0.005);
w=0.001;
L=0.007;
P=4*0.001;
Ta=25;
h=375;
Kf=175;
Kd=0.032;
Tb=75;
Ap=3.02*10^-3;
N=238;
Ac=10^-6;
m=92.6;
Lf=L-Ld;
Rtf=(cosh(m.*Lf)+(h./(m.*Kf)).*sinh(m.*Lf))./(sqrt(4*h.*(w)^3*Kf).*(sinh(m.*Lf)+h./(m.*Kf)).*cosh(m.*Lf));
R_fins=Rtf/N;
Rf_cond=Ld/(Kf*N*Ac);
Rd_cond=Ld/(Kd*(Ap-N*Ac));
Ad=Ld./(Kd*Rd_cond);
R_conv=1./(h*Ad);
q=(Tb-Ta)./(Rd_cond+R_conv)+(Tb-Ta)./(Rf_cond+R_fins);
Q=min(q);
figure
p = plot(Ld, q);
xlabel('Dust layer thickness, Ld (m)');
ylabel('Heat Rate, q(W)');
grid on;
fprintf("Total heat rate %.2f°C\n", Q);
Since only 1 data-tip can be added at a time, use a for loop -
%Define the x values to get data-tips for
vec = (1:5)/1e3;
for k=vec
%% Using tolerance to compare floating point numbers
%The highest significant digit of values in Ld is 5, corresponding to
%10^-5 or 1e-5, thus select a tolerance smaller than that
idx = abs(Ld-k)<1e-6;
datatip(p, Ld(idx), q(idx))
end
As the graph is monotonic, there is only 1 y-point corresponding to a single x-point. Thus we can directly use logical-indexing.
For other cases, the code might need modifications.

类别

Help CenterFile Exchange 中查找有关 Graphics Object Programming 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by