Sum two plots and plot the result
5 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Matthew Rotondaro
am 7 Sep. 2019
Kommentiert: Rik
am 6 Jul. 2023
Is there a simple way to take the sum of two plots that overlap and plot the result? X and Y are the same length for both.

1 Kommentar
Akzeptierte Antwort
Star Strider
am 7 Sep. 2019
One approach (assuming that they are functions of the same independent variable vector, so in addition to being the same lengths, they are evaluated at the same values of the independent variable):
XplusY = sum([X(:),Y(:)],2);
This creates a column vector result, since we don’t know the sizes of the original ‘X’ and ‘Y’. If you want it as a row vector, transpose it.
To sum only the values where ‘X’ is greater than or equal to ‘Y’:
L = X >= Y;
XL = X(L);
YL = Y(L);
XplusY = sum([XL(:),YL(:)],2);
since I am not certain what ‘overlap’ means here.
9 Kommentare
Star Strider
am 5 Jul. 2023
With respect to different independent variable ranges, the interpolation is still necessary, however they can only be summed in the ranges where all the curves exist. All the curves would need to be truncated to those limits, then the interpolated values summed, ignoring regions where they do not all overlap.
With respect to different resulutions, it is preferable to interpolate the higher resolution signal to match the values in the lower resolution signal. This avoids the problem of creating data in the lower resolution isgnal where none previously existed, as would be the problem if the lower resolution signal were interpolated to match the higher resolution signal, since the exact behaviour of the lower resolution signal at those points is obviously not known.
.
Rik
am 6 Jul. 2023
You might consider performing a moving average before downsampling. Otherwise you may introduce other effects (consider the situation where one of the curves is a sine and the resolution of the other curve is equal to the period of the sine).
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Surface and Mesh Plots finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!