help-octave
[Top][All Lists]
Advanced

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

Re: [help] the mean program in statitistical analysis


From: Jaroslav Hajek
Subject: Re: [help] the mean program in statitistical analysis
Date: Tue, 5 May 2009 09:23:40 +0200

On Tue, May 5, 2009 at 8:35 AM, febty febriani <address@hidden> wrote:
>
> hello everyone:
>
> I am running the mean program with using octave in shell program. I met
> error, but I don't know what its problem is.
> I have the 36000 lines of data ASCII. I did the mean program for each of 10
> lines data, so I should have 3600 lines in output files. But, actually, my
> output file is just 1020 lines.
>
> in terminal this is its error:
> error: fprintf: invalid stream number = -1
> error: evaluating for command near line 3, column 1
> error: Too many open files
>
> below is my complete program:
> #!/bin/bash
>
> for year in 2008
> do
> for month in 08
> do
> for day in 26
> do
> for hour in 01
> do
> for min in 00
> do
> for sec in 00
> do
>
> octave -q <<EOF
> fid=fopen("${year}${month}${day}${hour}${min}${sec}.dat","r");
> x=fscanf(fid,"%lf", [8 36000]);
> for i=0:36000
> x1=x(1,i*10+1:i*10+10);
> x2=x(2,i*10+1:i*10+10);
> x3=x(3,i*10+1:i*10+10);
> x4=x(4,i*10+1:i*10+10);
> x5=x(5,i*10+1:i*10+10);
> x6=x(6,i*10+1:i*10+10);
> x7=x(7,i*10+1:i*10+10);
> x8=x(8,i*10+1:i*10+10);
>
>
> x9=mean(x1);
> x10=mean(x2);
> x11=mean(x3);
> x12=mean(x4);
> x13=mean(x5);
> x14=mean(x6);
> x15=mean(x7);
> x16=mean(x8);
>
> fh2=fopen("${year}${month}${day}${hour}${min}${sec}.1Hz.dat","a+");

Since this line gets executed in each cycle, you open the file 36000
times, which likely causes your problem.
Either put a fclose after the following fprintf calls or better open
fh2 outside the loop (I see no need to reopen it).


> fprintf(fh2,'%f',x9);
> fprintf(fh2,'%f',x10);
> fprintf(fh2,'%f',x11);
> fprintf(fh2,'%f',x12);
> fprintf(fh2,'%f',x13);
> fprintf(fh2,'%f',x14);
> fprintf(fh2,'%f',x15);
> fprintf(fh2,'%f\n',x16);
>
> clear x8;
> clear x9;
> clear x10;
> clear x11;
> clear x12;
> clear x13;
> clear x14;
>
> endfor
> EOF
>
> done
> done
> done
> done
> done
> done
>
> Are there any ideas for my problem?
> Thanks very much in advance.
>
>
> regards,
> febty

Btw., you can probably write a much simpler and faster code by using
more vectorization. Also, it seems your code indexes out of bounds in
x.


-- 
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]