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]
0 件のコメント
採用された回答
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 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Linear and Nonlinear Regression についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!