help-octave
[Top][All Lists]
Advanced

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

Re: reading files


From: Ramesh Yapalparvi
Subject: Re: reading files
Date: Wed, 29 Jul 2009 14:00:12 -0700 (PDT)

If you want to read all the files with .txt files you can try these commands

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
snapshot= ['t10';'t11';'t12';'t13';'t14';'t15';'t16';'t17';'t18';'t19';'t20';'t21';'t22';'t23';'t24';'t25';'t26';'t27';'t28';'t29';'t30'];




[nn,mm]=size(snapshot);
nx=21;
Cx=3;
Nx=21;
n1x=21;
for i=1:nx
    name = strcat(snapshot(i:nn:nn*mm),'.dat');

    fid=fopen(name,'r');

    A1x = fscanf(fid,'%f',[3,inf]);
    A1x = A1x';
  
    [p,q]=size(A1x);

[p,q]=size(A1x);
    X(1:p,i) = A1x(:,Cx);
end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

what I am trying is to read all the data files together. These data files have 3 columns i. e [3,inf]...... If I want to read only the 1st column I give Cx=1

This will work since I got it working as well


--- On Wed, 7/29/09, James Sherman Jr. <address@hidden> wrote:

From: James Sherman Jr. <address@hidden>
Subject: Re: reading files
To: "Nuncio M" <address@hidden>
Cc: address@hidden
Date: Wednesday, July 29, 2009, 7:43 PM

It seems that you are generating the filename correctly, but all that
is, is a string (or vector of characters).  What you want is the data
that is contained in the file with that name.  Depending on the format
of that file there are a number of ways to read it in.  The simplest
way is if the file is just a series of numbers, you could try

fid = fopen(filename, 'r');
data = "" '%d');
fclose(fid);

Hope this helps.

On Wed, Jul 29, 2009 at 3:05 AM, Nuncio M<address@hidden> wrote:
> Dear all,
>            I am trying to read some files and made this code
>
>         ext='.txt';
>         prefix='file_';
>         for i=1:2
>         l=i;
>         mid=int2str(l);
>         filename=([prefix,mid,ext]);
>         disp(filename);
>         endfor
>                 untill this point the code worked as expected. I loaded the
> 'filename'
> using the load command. Problem starts when i assign variable to
> different columns in file. For example: x=filename(:,1)
> this gives a value "f" for  x which is the first character of filename,
> file_1.txt.  I understand the problem this way.  Octave treats the
> filename as a matrix and assign the first column 'f' to variable x or
> may not be.  I am new to octave and I cannot figure out a way to
> overcome this. Any help in this regard would be greatly appreciated
>
> regards
> nuncio
>
> --
> Nuncio.M
> Research Scientist
> National Center for Antarctic and Ocean research
> Head land Sada
> Vasco da Gamma
> Goa-403804
>
> _______________________________________________
> Help-octave mailing list
> address@hidden
> https://www-old.cae.wisc.edu/mailman/listinfo/help-octave
>
>

_______________________________________________
Help-octave mailing list
address@hidden
https://www-old.cae.wisc.edu/mailman/listinfo/help-octave


reply via email to

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