How to plot a marked point in a graph and connect it with other points?

Hello all,
I am trying to mark a specific point in the plot and need to connect it with other points. I have tried using plot(x_pos, y_pos) but i am getting an error. I have marked the points in the excel data. I am also attaching a demo plot on what i required. Please kindly help me. Thanks in advance.
My code:
Z = readtable('Atq100.xlsx') ;
data = table2array(Z) ;
N = size(data,2);
Nsp = N/2;
ttlc = {'x=10mm', 'x=250mm', 'x=500mm', 'x=1000mm', 'x=1500mm'};
xofst = [10 250 500 1000 1500];
figure
ylim([-1 1]*250)
xlim([0 1750])
hold on
for k = 1:Nsp
col = [2 1]+2*(k-1);
famp = 5;
datacol1 = data(:,col(1))*famp+xofst(k);
hp(k) = plot(datacol1, data(:,col(2)), 'LineWidth',2);
minx(k) = min(datacol1);
maxx(k) = max(datacol1);
plot([1;1]*[minx(k) maxx(k)], ([1;1]*ylim).', ':k', 'LineWidth',1)
plot([minx(1) maxx(1)]-minx(1)+minx(k), [0 0], '-k', 'LineWidth',1)
Line_Coordinates = [minx(1) maxx(1)]-minx(1)+minx(k);
LineLength = diff(Line_Coordinates);
end
hold off
hl = legend([hp], ttlc, 'Location','northeastoutside');

 Réponse acceptée

hello
this is a first attempt
the outer lines was fairly easy to plot
the two inner lines , it's a bit coded just to show a principle but there is yet no "scientific" method to pick the points . Now this is where you need to tell more about how to choose the inner points
so far this is where I am :
Z = readtable('Atq100.xlsx') ;
data = table2array(Z) ;
N = size(data,2);
Nsp = N/2;
ttlc = {'x=10mm', 'x=250mm', 'x=500mm', 'x=1000mm', 'x=1500mm'};
xofst = [10 250 500 1000 1500];
figure(1)
ylim([-1 1]*250)
xlim([0 1750])
hold on
for k = 1:Nsp
col = [2 1]+2*(k-1);
famp = 5;
datacol1 = data(:,col(1))*famp+xofst(k);
datacol2 = data(:,col(2));
minx(k) = min(datacol1);
maxx(k) = max(datacol1);
miny(k) = min(datacol2);
maxy(k) = max(datacol2);
%%%%%%%%%%%%%%%%%%%%% special code for inner line %%%%%%%%%%%%%%%%%%%%%
ll = length(datacol1);
ind1 = round(ll/(3.5+0.5*k));
ind2 = ll - round(ll/(2.5+0.5*k));
y_pos(k) = datacol2(ind1);
y_neg(k) = datacol2(ind2);
x_pos(k) = datacol1(ind1);
x_neg(k) = datacol1(ind2);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
hp(k) = plot(datacol1, datacol2, 'LineWidth',2);
plot([1;1]*[minx(k) maxx(k)], ([1;1]*ylim).', ':k', 'LineWidth',1)
plot([minx(1) maxx(1)]-minx(1)+minx(k), [0 0], '-k', 'LineWidth',1)
Line_Coordinates = [minx(1) maxx(1)]-minx(1)+minx(k);
LineLength = diff(Line_Coordinates);
end
plot(minx,miny,'dr',minx,maxy,'db')
plot(minx,miny,'r',minx,maxy,'b')
plot(x_pos,y_pos,'dr',x_neg,y_neg,'db')
plot(x_pos,y_pos,'--r',x_neg,y_neg,'--b')
hold off
hl = legend([hp], ttlc, 'Location','northeastoutside');

6 commentaires

Thank you for the response. I have selected the points on basis of the highest y value/2, which gives me some value and i am looking for the nearest value in the same y data and i need to plot it.
For example:
The highest vale in Y1 colume is 40.075/2 (cell B59 ) gives me a result 20.0375. The nearest corresponding values are in cells B16 and B117. I need to plot this point. Simiarly for the other y data. I hope you can understand what I need.
hello again
ok got it
this is the revised code and result
clc
clearvars
close all
Z = readtable('Atq100.xlsx') ;
data = table2array(Z) ;
N = size(data,2);
Nsp = N/2;
ttlc = {'x=10mm', 'x=250mm', 'x=500mm', 'x=1000mm', 'x=1500mm'};
xofst = [10 250 500 1000 1500];
figure(1)
ylim([-1 1]*250)
xlim([0 1750])
hold on
for k = 1:Nsp
col = [2 1]+2*(k-1);
famp = 5;
datacol1 = data(:,col(1))*famp+xofst(k);
datacol2 = data(:,col(2));
minx(k) = min(datacol1);
maxx(k) = max(datacol1);
miny(k) = min(datacol2);
maxy(k) = max(datacol2);
%%%%%%%%%%%%%%%%%%%%% special code for inner line %%%%%%%%%%%%%%%%%%%%%
ll = length(datacol1);
ind1 = round(ll/(3.5+0.5*k));
ind2 = ll - round(ll/(2.5+0.5*k));
y_pos(k) = maxy(k)/2; % initial guess
% find nearest value
[~,ind_pos] = min(abs(datacol2-y_pos(k)));
y_pos(k) = datacol2(ind_pos); % final value
x_pos(k) = datacol1(ind_pos); % final value
y_neg(k) = miny(k)/2; % initial guess
% find nearest value
[~,ind_neg] = min(abs(datacol2-y_neg(k)));
y_neg(k) = datacol2(ind_neg); % final value
x_neg(k) = datacol1(ind_neg); % final value
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
hp(k) = plot(datacol1, datacol2, 'LineWidth',2);
plot([1;1]*[minx(k) maxx(k)], ([1;1]*ylim).', ':k', 'LineWidth',1)
plot([minx(1) maxx(1)]-minx(1)+minx(k), [0 0], '-k', 'LineWidth',1)
Line_Coordinates = [minx(1) maxx(1)]-minx(1)+minx(k);
LineLength = diff(Line_Coordinates);
end
plot(minx,miny,'db',minx,maxy,'dr')
plot(minx,miny,'b',minx,maxy,'r')
plot(x_pos,y_pos,'dr',x_neg,y_neg,'db')
plot(x_pos,y_pos,'--r',x_neg,y_neg,'--b')
hold off
hl = legend([hp], ttlc, 'Location','northeastoutside');
Thank you for the revised code. But I think it is considering the Xvalues from the data. But i need to consider the Y values from the data but not from the axis. Can you please help me in modifying it.
hello
ok
this is the correction - inner points are defined as 50 % of Y data height -
clc
clearvars
close all
Z = readtable('Atq100.xlsx') ;
data = table2array(Z) ;
N = size(data,2);
Nsp = N/2;
ttlc = {'x=10mm', 'x=250mm', 'x=500mm', 'x=1000mm', 'x=1500mm'};
xofst = [10 250 500 1000 1500];
figure(1)
ylim([-1 1]*250)
xlim([0 1750])
hold on
for k = 1:Nsp
col = [2 1]+2*(k-1);
famp = 5;
datacol1 = data(:,col(1))*famp+xofst(k);
datacol2 = data(:,col(2));
minx(k) = min(datacol1);
maxx(k) = max(datacol1);
miny(k) = min(datacol2);
maxy(k) = max(datacol2);
%%%%%%%%%%%%%%%%%%%%% special code for inner line %%%%%%%%%%%%%%%%%%%%%
x_init = (maxx(k)+minx(k))/2; % initial guess
% find nearest value
aa = round(length(datacol1)/2);
datacol1_pos = datacol1(aa+1:end);
datacol1_neg = datacol1(1:aa);
datacol2_pos = datacol2(aa+1:end);
datacol2_neg = datacol2(1:aa);
[~,ind_pos] = min(abs(datacol1_pos-x_init));
[~,ind_neg] = min(abs(datacol1_neg-x_init));
y_pos(k) = datacol2_pos(ind_pos); % final value
x_pos(k) = datacol1_pos(ind_pos); % final value
y_neg(k) = datacol2_neg(ind_neg); % final value
x_neg(k) = datacol1_neg(ind_neg); % final value
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
hp(k) = plot(datacol1, datacol2, 'LineWidth',2);
plot([1;1]*[minx(k) maxx(k)], ([1;1]*ylim).', ':k', 'LineWidth',1)
plot([minx(1) maxx(1)]-minx(1)+minx(k), [0 0], '-k', 'LineWidth',1)
Line_Coordinates = [minx(1) maxx(1)]-minx(1)+minx(k);
LineLength = diff(Line_Coordinates);
end
plot(minx,miny,'db',minx,maxy,'dr')
plot(minx,miny,'b',minx,maxy,'r')
plot(x_pos,y_pos,'dr',x_neg,y_neg,'db')
plot(x_pos,y_pos,'--r',x_neg,y_neg,'--b')
hold off
hl = legend([hp], ttlc, 'Location','northeastoutside');
Thank you so much for the help. It is exactly what i need. Have a nice weekend.
My pleasure
Have a nice weekend.too !

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur 2-D and 3-D Plots dans Centre d'aide et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by