Hi, I understand you are trying to plot common elements between two datasets. You can use intersect function to get an overlap between two datasets.Here is a sample code for it. clc;clear all;
x1 = [1, 2, 3, 4, 5, 6, 7];
y1 = [1, 4, 9, 16, 25, 36, 49];
x2 = [1.5, 3, 4.5, 6];
y2 = [10, 6, 4, 0];
[common_x1x2,locx1,locx2 ] = intersect(x1,x2);
common_y1=y1(locx1);
common_y2=y2(locx2);
plot(common_x1x2,common_y1,common_x1x2,common_y2);
You Can also plot both the dataset.
clc;clear all;
x1 = [1, 2, 3, 4, 5, 6, 7];
y1 = [1, 4, 9, 16, 25, 36, 49];
x2 = [1.5, 3, 4.5, 6];
y2 = [10, 6, 4, 0];
diffx2x1=setdiff(x2,x1);
x1new=[x1,diffx2x1];
y1new=[y1,zeros(1,length(diffx2x1))];
diffx1x2=setdiff(x1,x2);
x2new=[x2,diffx1x2];
y2new=[y2,zeros(1,length(diffx1x2))];
plot(x1new,y1new,'o')
hold on
plot(x2new,y2new,'o')
hold off
Best Answer