intersection between a many plots and a line
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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])
0 commentaires
Réponses (2)
Walter Roberson
le 1 Mai 2023
Modifié(e) : Walter Roberson
le 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
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
0 commentaires
Matt J
le 1 Mai 2023
Modifié(e) : Matt J
le 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);
0 commentaires
Voir également
Catégories
En savoir plus sur Annotations dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!