adding up values from multiple plots

  • Follow


Hello,
Is there anyway i can add up up all the values from multiple discrete function plots without going through all them and looking at all of their values and manually adding them.
thx in advance.
0
Reply garlicenator (1) 10/14/2008 4:29:02 AM

"john geo" <garlicenator@gmail.com> wrote in message <gd176e$rgs$1@fred.mathworks.com>...

> Is there anyway i can add up up all the values from
> multiple discrete function plots without going through all
> them and looking at all of their values and manually
> adding them.

Lines = findobj(0, 'Type', 'line');
nLines = length(Lines);
Xvals = cell(nLines,1);
Yvals = cell(nLines,1);
for K=1:nLines
  Xvals{K} = get(Lines(K),'XData');
  Yvals{K} = get(Lines(K),'YData');
end

AllX = unique(reshape( cell2mat(Xvals), [], 1));
numX = length(AllX);
Ysum = zeros(numX, 1);

for K = 1:nLines
  TheseY = interp(xvals{K}, yvals{K}, Allx);
  Ysum = Ysum + TheseY;
end


End result: a vector AllX of all the different X values
over all of the plots, and a vector Ysum of the sums of
all of the Y values that would be interpolated at those
different X values.

Caution: if one plot has an X point at (say) 1.5
exactly, and another plot has an X point that is
intended to be the same, but due to a different
calculation route comes out as 1.5+eps(1.5), then
the unique() step will believe them to be different
points, and so will produce an output for 1.5 and
another output for 1.5+eps(1.5) . This can be handled
(if it is not desired) by refining the unique() step of
the algorithm.

The code can be simplified if it is -certain- that
all of the X values are intended to represent the same
points on all of the graphs, and simplified considerably
further if it is -certain- that there are also exactly
the same number of X/Y pairs for each of the graphs.
As written, the code does not assume that the graphs
have the same X axes nor the same number of points per
graph.
0
Reply roberson2 (8067) 10/14/2008 5:28:01 AM


1 Replies
76 Views

(page loaded in 0.009 seconds)

Similiar Articles:













7/23/2012 12:26:01 PM


Reply: