How to do the summation of two graphs?

22 visualizzazioni (ultimi 30 giorni)
Dear Colleagues,
I have two different graphs with different Y values and x values. it is hard to predict an equation with minimum error for this graph. Is there anyway to plot the sum of following two graphs?
Graph 1=[
414.00 1.00
400.00 1.00
384.00 1.00
381.00 1.00
367.00 1.00
348.00 1.00
321.00 1.19
308.00 1.39
299.00 1.61
279.00 1.78
275.00 2.00
264.00 2.59
272.00 3.39
259.00 3.59
262.00 4.00
274.00 4.59
286.00 5.63
305.00 6.00
341.00 6.19
366.00 6.39
395.00 7.00
408.00 7.19
408.00 7.41
394.00 7.61
408.00 7.81
408.00 8.00
412.00 8.19]
Graph 2=[688.00 1.00
690.00 1.00
672.00 1.00
644.00 1.00
638.00 1.00
660.00 1.01
626.00 1.22
602.00 1.40
602.00 1.59
604.00 1.80
582.00 2.00
560.00 2.22
574.00 2.40
563.00 2.60
557.00 2.79
565.00 3.00
593.00 3.22
602.00 3.40
598.00 3.59
606.00 3.79
592.00 4.00
607.00 4.22
593.00 4.40
603.00 4.59
589.00 4.79
602.00 5.00
581.00 5.22
591.00 5.40
577.00 5.59
585.00 5.80
572.00 6.00
567.00 6.22
559.00 6.40
560.00 6.59
572.00 6.80
592.00 7.00
635.00 7.22
675.00 7.40
702.00 7.59
709.00 7.80
726.00 8.00
728.00 8.22
725.00 8.41
751.00 8.60
775.00 8.80
785.00 9.00
780.00 9.22
794.00 9.41]
1st column is Y axis and second column is x axis.
Thanks in advance.

Risposta accettata

Star Strider
Star Strider il 30 Mag 2016
I don’t understand what you mean by ‘sum’. The two matrices have different numbers of elements, so you can shorten the longer one, or you can interpolate one to the x-values of the other one with interp1 (without extrapolating), but you cannot do any calculations with them as they currently exist.
What equation are you trying to fit to them?
  4 Commenti
Nadeera Gunartna
Nadeera Gunartna il 1 Giu 2016
Thank you very much. I appreciate it.
Star Strider
Star Strider il 1 Giu 2016
My pleasure.
If my Answer solved your problem, please Accept it.

Accedi per commentare.

Più risposte (1)

John BG
John BG il 31 Mag 2016
you have 2 signals
y1=[ 414.00 1.00 400.00 1.00 384.00 1.00 381.00 1.00 367.00 1.00 348.00 1.00 321.00 1.19 308.00 1.39 299.00 1.61 279.00 1.78 275.00 2.00 264.00 2.59 272.00 3.39 259.00 3.59 262.00 4.00 274.00 4.59 286.00 5.63 305.00 6.00 341.00 6.19 366.00 6.39 395.00 7.00 408.00 7.19 408.00 7.41 394.00 7.61 408.00 7.81 408.00 8.00 412.00 8.19]
y2=[688.00 1.00 690.00 1.00 672.00 1.00 644.00 1.00 638.00 1.00 660.00 1.01 626.00 1.22 602.00 1.40 602.00 1.59 604.00 1.80 582.00 2.00 560.00 2.22 574.00 2.40 563.00 2.60 557.00 2.79 565.00 3.00 593.00 3.22 602.00 3.40 598.00 3.59 606.00 3.79 592.00 4.00 607.00 4.22 593.00 4.40 603.00 4.59 589.00 4.79 602.00 5.00 581.00 5.22 591.00 5.40 577.00 5.59 585.00 5.80 572.00 6.00 567.00 6.22 559.00 6.40 560.00 6.59 572.00 6.80 592.00 7.00 635.00 7.22 675.00 7.40 702.00 7.59 709.00 7.80 726.00 8.00 728.00 8.22 725.00 8.41 751.00 8.60 775.00 8.80 785.00 9.00 780.00 9.22 794.00 9.41]
Ly1=length(y1)
Ly2=length(y2)
Ly1 =
54.00
Ly2 =
96.00
You may want to interpolate the shorter signal. The other way round is also possible, but rather than killing samples, you may choose to add them, just for the sake of, if only potentially, not losing information.
ny1 and ny2 are respective reference vectors:
ny1=[1:1:Ly1]
ny2=[1:1:Ly2]
stretch ny1 to reach ny2:
ny1_stretch=linspace(1,Ly2,Ly1)
and interpolate (linear)
y1_interp=interp1(ny1_stretch,y1,ny2)
or interpolate (cubic)
y1_interpc=interp1(ny1_stretch,y1,ny2,'spline')
Now you can combine y1_interp or y1_interpc with y2 in any vector operation or on same plot
plot(ny2,y1_interp,'Color','r','LineWidth',1.5);
hold on;plot(ny2,y2,'Color','b','LineWidth',1.5);
hold on;plot(ny2,y1_interpc,'Color','g','LineWidth',1.5);grid on
.
If you find this answer of any help solving your question,
please click on the thumbs-up vote link,
thanks in advance
John
  1 Commento
Nadeera Gunartna
Nadeera Gunartna il 31 Mag 2016
Thank you for the answer, but my question was I need to plot the summation of that two graphs (lets say 1+2=3) like that. anyway thank you for your friendly advice.

Accedi per commentare.

Categorie

Scopri di più su Descriptive Statistics in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by