"Barry Williams" <barry.r.williamsnospam@saic.com> wrote in message <kk3fi7$or9$1@newscl01ah.mathworks.com>...
> "J K" wrote in message <kk31am$hop$1@newscl01ah.mathworks.com>...
> > http://www.mathworks.com/matlabcentral/newsreader/view_thread/300254
> > I refer to link above, but I don't quite get the part
> > the_area = trapz(x(1:idx),y(1:idx))trapz(x((idx+1):end),y((idx+1):end)
> >
> > What does idx mean?
> >
> > I'm a novice Matlab user, please be patient with me.
> >
> > Thank you.
>
> The OP asked how to pick out the area enclosed by curves with the same x and y values at the minimum and maximum values of x. The function max can have two outputs. The first is the maximum value returned by the function, and the second is the index of the maximum value. The line below looks for the maximum value of of x, returns it as trash, and the index of the maximum value as idx:
> [trash, idx] = max(x_values);
> We have to assume that all of the x and y data for both curves are contained in a single array of x values and a single array of y values. So [trash idx] = m(x_values) returns the maximum value of x as trash, which we don't need, and its index value as idx.
> The index value of the first x data point is, of course, 1. So x(1:idx) then represents all the values of x in the first curve. The next point in the x array, x(1+idx), is the first x point in the other curve, and x(1+idx:end) includes all of the x values in the second curve. The rest just captures the corresponding y values and uses trapz to integrate and then subtract the lower curve from the upper one, giving the enclosed area.
> Barry
There's something wrong with this expression. My x values is V, and my y values is Pressure. I need to find the work done, that's area enclosed by the plot. But I get error.
From Matlab:
??? Work = trapz(V(1:idx),Pressure(1:idx))trapz(V((idx+1):end),Pressure((idx+1):end)

Error: Expression or statement is incorrectpossibly unbalanced (, {, or [.
