51 views (last 30 days)

I have collected spectral data from two instruments and stitched the spectra together (simple concatenation). I want to make a plot tht shows how the spectra have been stitched together.

Spectrum 1 ranges from 180-1050, and Spectrum2 ranges from 120-1200. When I plot them, the lines overlap because the x values are repeated in each range.

How can I make Spectrum2 plot after Spectrum1 on it's own x-values?

This is what I have written:

data = xlsread('_______','Load_LL','D1:SJE4');

x = data(1,:);

PC1 = data(2,:);

PC2 = data(3,:);

PC3 = data(4,:);

plot(x,PC1,'-k',...

'LineWidth',0.75);

ylim([-0.3 0.1])

ylabel('PC-1');

set(h1,'FontName','Times New Roman','FontSize',10);

set(h1,'xtick',[])

And I get this:

I want something that looks more like this:

I tried plotting each spectrum as a subplot, which got me closer to my goal, but the two spectra should not take up the same space on the x axis (Spectrum1 has farrrr more variables).

How can I plot each y value with it's associated x vlue without getting overlap between repeted x values?

Athul Prakash
on 23 Feb 2020

Looks like you want the plots to appear side-by-side.

Maybe you can concatenate 'PC1', 'PC2' and 'PC3' into one longer vector, while also creating a different x axis for plotting?

newY = [PC1, PC2, PC3];

distX = max(x)-min(x)+1;

newX = [x, x+distX, x+2*distX];

plot(newX, newY);

Hope this helps you.

Opportunities for recent engineering grads.

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

Start Hunting!
## 2 Comments

## Direct link to this comment

https://la.mathworks.com/matlabcentral/answers/506673-how-to-plot-a-line-with-repeated-values-of-x#comment_800103

⋮## Direct link to this comment

https://la.mathworks.com/matlabcentral/answers/506673-how-to-plot-a-line-with-repeated-values-of-x#comment_800103

## Direct link to this comment

https://la.mathworks.com/matlabcentral/answers/506673-how-to-plot-a-line-with-repeated-values-of-x#comment_962065

⋮## Direct link to this comment

https://la.mathworks.com/matlabcentral/answers/506673-how-to-plot-a-line-with-repeated-values-of-x#comment_962065

Sign in to comment.