Horizontal line up to graph line

Hi everyone,
I want to put horizontal line to my graph . The line extend up to end of the graph however it should be cut at point to graph line and horizontal line intersect. Also I want to change chracter to subscript 1 in S1 . How I do it? Thanks.
clear
clc
y = [0.5 1 2 3.5 6 8 10.2 14 18 21 35 41 58 60.5 66 70 90 100];
y1 = [0 0.5 1 2 3.5 6 8 10.2 14 18 21 35 37.32]; % Trapezoidal integralin tanım aralığı (y1)
u = [0.271 0.518 1.113 1.93 3.137 4.157 5.32 7.28 9.22 10.79 11.3 11.52 11.55 11.51 11.58 11.6 11.59 11.50];
u1 = [0 0.271 0.518 1.113 1.93 3.137 4.157 5.32 7.28 9.22 10.79 11.3 11.385] % Trapezoidal integralin tanım aralığı (u1)
U = u(end); % Free stream velocity
u99=0.99.*U;
L=interp1(u(1:13),y(1:13),u99); % Sınır tabakası
S1 = trapz(y1,1-u1/U); % Integral of (1-u/U) w.r.t. y
S2 = trapz(y1,(u1/U).*(1-u1/U)); % Integral of (u/U)*(1-u/U) w.r.t. y
S3 = trapz(y1,(u1/U).*(1-(u1.*u1)/(U.*U))); % Integral of (u/U)*(1-(u/U)^2) w.r.t. y
fprintf('\nU = %6.2f (mm)\ndelta1 = %6.2f (mm)\ndelta2 = %6.2f (mm) \ndelta3 = %6.2f (mm)\n',...
U,S1,S2,S3);
plot(u,y,'p-','LineWidth',1,'Marker','square'); xlabel('u (m/s)'); ylabel('y (mm)');
hold on
plot([0 U],S1*[1 1],'r--','color',[0 0 1]); % yatay cizgi y = S1
theText = sprintf('\\delta1 = %4.3f',S1);
text(0.05*U,1.2*S1,theText,'FontSize',12); % yazı karakteristikleri

 Accepted Answer

Try this —
y = [0.5 1 2 3.5 6 8 10.2 14 18 21 35 41 58 60.5 66 70 90 100];
y1 = [0 0.5 1 2 3.5 6 8 10.2 14 18 21 35 37.32]; % Trapezoidal integralin tanım aralığı (y1)
u = [0.271 0.518 1.113 1.93 3.137 4.157 5.32 7.28 9.22 10.79 11.3 11.52 11.55 11.51 11.58 11.6 11.59 11.50];
u1 = [0 0.271 0.518 1.113 1.93 3.137 4.157 5.32 7.28 9.22 10.79 11.3 11.385]; % Trapezoidal integralin tanım aralığı (u1)
U = u(end); % Free stream velocity
u99=0.99.*U;
L=interp1(u(1:13),y(1:13),u99); % Sınır tabakası
S1 = trapz(y1,1-u1/U); % Integral of (1-u/U) w.r.t. y
S2 = trapz(y1,(u1/U).*(1-u1/U)); % Integral of (u/U)*(1-u/U) w.r.t. y
S3 = trapz(y1,(u1/U).*(1-(u1.*u1)/(U.*U))); % Integral of (u/U)*(1-(u/U)^2) w.r.t. y
fprintf('\nU = %6.2f (mm)\ndelta1 = %6.2f (mm)\ndelta2 = %6.2f (mm) \ndelta3 = %6.2f (mm)\n',...
U,S1,S2,S3);
U = 11.50 (mm) delta1 = 11.64 (mm) delta2 = 4.21 (mm) delta3 = 6.55 (mm)
Ui = interp1(y, u, S1) % 'u' Limit (Intercept) Of Dashed Line
Ui = 6.0630
plot(u,y,'p-','LineWidth',1,'Marker','square'); xlabel('u (m/s)'); ylabel('y (mm)');
hold on
plot([0 Ui],S1*[1 1],'r--','color',[0 0 1]); % yatay cizgi y = S1
% plot([0 U],S1*[1 1],'r--','color',[0 0 1]); % yatay cizgi y = S1
theText = sprintf('\\delta_1 = %4.3f',S1); % Convert To Subscript
text(0.05*U,1.2*S1,theText,'FontSize',12, 'Vert','bottom'); % yazı karakteristikleri
The dashed line now only extends to the point of interception with the blue line.
.

More Answers (1)

y = [0.5 1 2 3.5 6 8 10.2 14 18 21 35 41 58 60.5 66 70 90 100];
y1 = [0 0.5 1 2 3.5 6 8 10.2 14 18 21 35 37.32]; % Trapezoidal integralin tanım aralığı (y1)
u = [0.271 0.518 1.113 1.93 3.137 4.157 5.32 7.28 9.22 10.79 11.3 11.52 11.55 11.51 11.58 11.6 11.59 11.50];
u1 = [0 0.271 0.518 1.113 1.93 3.137 4.157 5.32 7.28 9.22 10.79 11.3 11.385] % Trapezoidal integralin tanım aralığı (u1)
u1 = 1×13
0 0.2710 0.5180 1.1130 1.9300 3.1370 4.1570 5.3200 7.2800 9.2200 10.7900 11.3000 11.3850
U = u(end); % Free stream velocity
u99=0.99.*U;
L=interp1(u(1:13),y(1:13),u99); % Sınır tabakası
S1 = trapz(y1,1-u1/U); % Integral of (1-u/U) w.r.t. y
S2 = trapz(y1,(u1/U).*(1-u1/U)); % Integral of (u/U)*(1-u/U) w.r.t. y
S3 = trapz(y1,(u1/U).*(1-(u1.*u1)/(U.*U))); % Integral of (u/U)*(1-(u/U)^2) w.r.t. y
fprintf('\nU = %6.2f (mm)\ndelta1 = %6.2f (mm)\ndelta2 = %6.2f (mm) \ndelta3 = %6.2f (mm)\n',...
U,S1,S2,S3);
U = 11.50 (mm) delta1 = 11.64 (mm) delta2 = 4.21 (mm) delta3 = 6.55 (mm)
plot(u,y,'p-','LineWidth',1,'Marker','square'); xlabel('u (m/s)'); ylabel('y (mm)');
hold on
% plot([0 U],S1*[1 1],'r--','color',[0 0 1]); % yatay cizgi y = S1
yline(S1, 'b--'); % horizontal line
theText = sprintf('\\delta_1 = %4.3f',S1); % use _ for subscript
text(0.05*U,1.2*S1,theText,'FontSize',12); % yazı karakteristikleri

1 Comment

jack london
jack london on 12 Dec 2021
Edited: jack london on 12 Dec 2021
Thank you but it still seems to extend after graph line. I want to trim at point the graph line and horizontal line intersect(about u=6).

Sign in to comment.

Categories

Find more on MATLAB in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!