Combining XY plots with arbitrary line shapes (combining spectra)

조회 수: 8 (최근 30일)
todd eliason
todd eliason 2020년 5월 11일
편집: Guru Mohanty 2020년 5월 14일
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