# Find Intersections of 2 Curves in MATLAB with Mapping Toolbox

## Toolbox Required

When you use the polyxpoly function the first time, you would be notified that you do not have the Mapping Toolbox. You should follow the instruction to install it before you can use the toolbox.

Just click on the underlined Mapping Toolbox to open the Add-On Explorer to finish the installation.

After the installation, you can try like the following

`[xi, yi] = polyxpoly(x1, y1, x2, y2);`

xi and yi are the x and y coordinates of the intersections. Following is a live example. The raw data is available in the Excel file below, you can import it to MATLAB to have hand-on experience.

## Code Snippet

```% labplot comes from the lab data
Vi = labplot{:, 1};
Vo = labplot{:, 2};

hold on;
title("74LS00 V_{ON} and V_{OFF}");
xlabel("V_i/v");
ylabel("V_O/V");

plot(Vi, Vo, '-x');

step = 0.02;
% V_off
line_off_range = 0:step:5;
line_on_range = line_off_range;
line_off = ones(5 / step + 1, 1) * 2.4;
% plot the intersect
[x_off, y_off] = polyxpoly(Vi, Vo, line_off_range, line_off);
plot(x_off, y_off, '*');
% plot the horizontal line
line_off_range = 0:step:x_off;
line_off = ones(ceil(x_off / step), 1) * 2.4;
plot(line_off_range, line_off, ':');
%plot the vertical line
plot(ones(5 / step + 1, 1) * x_off, 0:step:5, '--');

% V_on
% line_on_range = line_off_range;
line_on = ones(5/step + 1, 1) * 0.4;
[x_on, y_on] = polyxpoly(Vi, Vo, line_on_range, line_on);
% plot the horizontal 0.4 line
line_on_range = 0:step:x_on;
line_on = ones(ceil(x_on / step), 1) * 0.4;
plot(line_on_range, line_on, ':');

% plot the intersect and mark on x-axis
plot(x_on, y_on, '*');
%plot the vertical V_on line
plot(ones(5/step + 1, 1) * x_on, 0:step:5, '--');

% legend
legend('curve', '', 'V_{O}=2.4V',  sprintf("V_{OFF}=%.3fV",x_off), 'V_{O}=0.4V', '', sprintf("V_{ON}=%.3fV", x_on));```

### Plot Result

As you can see, the intersect of the characteristic curve and the 2 horizontal lines are calculated and marked on the plot. And 2 vertical lines are drawn passing through the 2 intersects respectively.