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

7 ビュー (過去 30 日間)
Vishnuvardhan Naidu Tanga 2021 年 10 月 14 日
コメント済み: Mathieu NOE 2021 年 10 月 15 日
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:
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');

サインインしてコメントする。

採用された回答

Mathieu NOE 2021 年 10 月 14 日
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 :
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 件のコメント表示 5 件の古いコメント非表示 5 件の古いコメント
Mathieu NOE 2021 年 10 月 15 日
My pleasure
Have a nice weekend.too !

サインインしてコメントする。

カテゴリ

Find more on Discrete Data Plots in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by