Hi matlab experts,

I didn't think daniweb has a matlab forum so I went over to another math forum to ask for matlab help. but i think it's either I am too stupid for the mathematicians or they are too smart to realize that it is NOT obvious what i should do from just function and math theory names thrown at me... conclusion: daniweb explains the best =)

now, since there is no official matlab forum here, I hope I can just try my luck.

Question:
I have some experimental data points plotted y against t where t = 0 to 30, 0.5 interval. I want to find area under graph from, say, t = 0.832 to 5.672

How can I do it in matlab? Please show exact step by step as far as possible, because I am a matlab noob.

So far I have seen example from trapz and quads, but the also require the function f(t) to be known, which is not possible in my case because mine is experimental data.

I expect it to be something like this (psuedocode)

f = plot(t, y)
A = integrate(f, t1, t2)

MATLAB has an "area" function, but I think it requires a known function, which doesn't help you, since your data is experimental.

I am not aware of MATLAB having the sort of function you want, unless they have added this capability recently.

You might want to check out PCHQA:

http://www.ewp.rpi.edu/hartford/~ernesto/ernesto/Courses/C_S97/nc/NMS/CH04/pchqa.f

It accepts experimental data, and does a numerical integration on it, creating an interpolating spline wherever data is needed in order to give the results meaning. (If the integration used only the data points, the results would probably be meaningless, so the algorithm must interpolate at certain points in order to give the results meaning.)

However, there is one drawback: PCHQA is written in FORTRAN

Thanks DavidB,

Although this is actually long overdue and I had gotted my way around finally by writing some matlab code myself...

But I have to say that your reply is probably the most helpful I got. I mean seriously. Saying there is no such function for experimental data and then offering alternatives is really all I need to proceed. Thanks again.

Take the sum and multiply by the step size. It's that easy.

Or see Simpson's method.

Edit: Gah, of course you have to have fractional endpoints. So treat the first and last segments specially.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.