Combining XY plots with arbitrary line shapes (combining spectra)

8 次查看(过去 30 天)
I have two datasets (spectra) that are with respect to the same x y variables however the bounds/step size of x do not match. However the x values can overlap between the datasets. I want to create a curve that contains both of the datasets. Since the datasets are quite large this preculdes doing it manually, I included some general data below if that helps for the explanation.
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]

采纳的回答

Guru Mohanty
Guru Mohanty 2020-5-14
编辑:Guru Mohanty 2020-5-14
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 Element between x1 & x2
common_y1=y1(locx1); % Corresponding Element in y1
common_y2=y2(locx2); % Corresponding Element in y2
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

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Linear and Nonlinear Regression 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by