[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: How to fix this error?
From: |
James Sherman Jr. |
Subject: |
Re: How to fix this error? |
Date: |
Wed, 22 Jul 2009 23:06:03 -0400 |
First, the fscanf error is because the fid that you give it (from
fopen) is -1 which means that fopen failed for whatever reason. You
should probably check that, after fopen is called, that fid is greater
than 0, and thus a valid fid.
Secondly, the reason that it is probably failing is that you're
indexing into your ratio matrix incorrectly (or at least not the way I
think you mean to index it). When you have ratio typed out like that,
octave uses it like a 2D array where (for example) the 2,2 element is
1 (out of t11). I think a better way to get what you're after is to
try something like this:
ratio = [10, 11, 12, 13, 14, 15, 16, ..., 120];
for i = 1:length(ratio)
filename = sprintf('t%d.dat', ratio(i));
fid = fopen(filename, 'r');
if (fid < 0)
printf('Couldn't open file %s', filename);
else,
<rest of your function>
end
end
Hope this helps.
On Wed, Jul 22, 2009 at 10:47 PM, Ramesh
Yapalparvi<address@hidden> wrote:
> Hi all,
>
> I am trying to run a mfile in octave. I am reading a bunch of files in this
> form
>
> ratio= ['t10 ';'t11 ';'t12 ';'t13 ';'t14 ';'t15 ';'t16 ';'t17
> ';'t18 ';'t19 '; 't110 ';'t111 ';'t1115';'t112 ';'t113 ';'t114
> ';'t115 ';'t116 ';'t117 ';'t118 ';'t119 '; 't120 '];
>
> where t10.... are data files containing 3 columns
>
> I give this command
>
> [nn,mm]=size(ratio)
>
> for i=1:nx (nx=22)
> name = strcat(ratio(i:nn:nn*mm),'.dat');
>
> fid=fopen(name,'r');
>
> A1x = fscanf(fid,'%f',[3,inf]);
> A1x = A1x';
>
> I get the following error
>
> error: fscanf: invalid stream number = -1
>
>
> I know this is something related to fscanf. If anybody has any idea please
> let me know. Thanks
>
> Ramesh
>
>
>
> _______________________________________________
> Help-octave mailing list
> address@hidden
> https://www-old.cae.wisc.edu/mailman/listinfo/help-octave
>
>