help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: how to do trapz on a data file


From: Jaroslav Hajek
Subject: Re: how to do trapz on a data file
Date: Sat, 17 Oct 2009 21:11:02 +0200

On Sat, Oct 17, 2009 at 6:19 PM, Nunzio Losacco
<address@hidden> wrote:
> Hi everyone,
>
> I've just installed octave 3.2.3 and I'm a complete newbie. What I need most
> is a quick command to get the area under a curve. The curve is made of
> columns 1 and 3 of a file like this which I use to plot with gnuplot:
>
> 1.000000000000e+02 0.000000000000e+00 6.917126169316e-04
> 9.798418000000e+01 0.000000000000e+00 6.923512999807e-04
> 9.596836000000e+01 0.000000000000e+00 6.947493914720e-04
> 9.400841000000e+01 0.000000000000e+00 7.045027864544e-04
>
> and so forth...
>
> I use to import the file in a spreadsheet and then do a trapezoidal
> integration "by hand"
>
> sum((y[i-1]+y[i])*(x[i]-x[i-1])/2) for i=2:n
>
> being i the row and n the number of rows.
>
> But this is very time wasting when doing loads of parametric analyses. How
> can I get this quickly with octave?
> There would be any difference if the file had a header?
>
> Thanks for your help,
>
> N.
>

data = load ("datafile");
trapz (data (:,1), data (:,3))


-- 
RNDr. Jaroslav Hajek
computing expert & GNU Octave developer
Aeronautical Research and Test Institute (VZLU)
Prague, Czech Republic
url: www.highegg.matfyz.cz


reply via email to

[Prev in Thread] Current Thread [Next in Thread]