Filter löschen
Filter löschen

intersection between a many plots and a line

2 Ansichten (letzte 30 Tage)
Ethan Woodvine
Ethan Woodvine am 1 Mai 2023
Bearbeitet: Matt J am 1 Mai 2023
Hello!
Im been looking and cant find a definitive soltion to how to find the intersection between a yline and multiple plots
between the plots and the yline i need to find the intersecting points but I cant seem to find out how to do it.
any help would be great thanks!
figure(1) % Q4
plot(SNR,PERSF7,'-or','MarkerSize', 8,'LineWidth',2)
hold on
plot(SNR,PERSF8,'-*','MarkerSize', 8,'LineWidth',2)
plot(SNR,PERSF9,'-diamond','MarkerSize', 8,'LineWidth',2)
plot(SNR,PERSF10,'-x','MarkerSize', 8,'LineWidth',2)
plot(SNR,PERSF11,'-^','MarkerSize', 8,'LineWidth',2)
plot(SNR,PERSF12,'-square','MarkerSize', 8,'LineWidth',2)
% 5% point
yline(0.05)
hold off
xlim([-25 0])
ylim([0 1])

Antworten (2)

Walter Roberson
Walter Roberson am 1 Mai 2023
Bearbeitet: Walter Roberson am 1 Mai 2023
There is no built-in facility to take the intersection between yline or xline, with anything.
You are looking for the places where (PERSF7 - 0.05) touches or crosses 0, (PERSF8 - 0.05) touches or crosses 0, and so on.
rng(655321)
PERSF7 = randn(1,50) / 5;
SNR = (1:numel(PERSF7))/10;
target_y = 0.05;
plot(SNR, PERSF7);
yline(target_y);
locs = find((PERSF7(1:end-1)-target_y) .* (PERSF7(2:end) - target_y) <= 0);
locs
locs = 1×20
3 5 6 9 11 12 16 17 22 23 24 25 31 32 34 36 41 42 48 49
This says that there is a zero crossing between PERSF7(3) and PERSF7(4), between PERSF7(5) and PERSF7(6), between PERSF7(6) and PERSF7(7), between PERSF7(9) and PERSF7(10) and so on.
for k = 1 : numel(locs)
SNR_crossing(k) = interp1(PERSF7(locs(k):locs(k)+1), SNR(locs(k):locs(k)+1), target_y);
end
figure();
plot(SNR, PERSF7);
hold on
plot(SNR_crossing, target_y .* ones(size(SNR_crossing)), 'r*');
hold off

Matt J
Matt J am 1 Mai 2023
Bearbeitet: Matt J am 1 Mai 2023
You could use linexlines2D from this FEX download,
rng(655321)
PERSF7 = randn(1,50) / 5;
SNR = (1:numel(PERSF7))/10;
target_y = 0.05;
XY=[SNR;PERSF7];
[XYout, map]=linexlines2D(XY(:,1:end-1),XY(:,2:end), [0,1,-target_y]);
plot(SNR, PERSF7, XYout(1,:), XYout(2,:),'rx');
yline(target_y);

Community Treasure Hunt

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

Start Hunting!

Translated by