Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
textread

Subject: textread

From: Jong-Hoon Kim

Date: 11 Sep, 2008 13:10:45

Message: 1 of 4

Hi helpers,

I was wondering if somebody would help me find a better way to solve
my problem.
I have data files that have variable column and row numbers. At the
moment I am using 'textread' function to read the data and do some
simple analysis. All my data are numbers except the header lines.

In the code snippet below, I have "%f%f%f%f%f%f%f%f%f%f%f%f ", but in
case I have more columns, I need to add more "%f"s. I don't like this
idea. I understand that if the data has fewer columns, then that's
not a problem. This suggest that I can avoid problems simply by
having lots of "%f"'s in the beginning. But I expect that there would
be better ways. I would appreciate your suggestions.


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    data = textread( fullfile(expDir,subDir,dataFile(j).name), ...
        ' %f%f%f%f%f%f%f%f%f%f%f%f ','headerlines',numHeaderLine, ...
        'commentstyle', 'shell' );
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

Subject: textread

From: dpb

Date: 11 Sep, 2008 14:08:10

Message: 2 of 4

Jong-Hoon Kim wrote:
...
> I have data files that have variable column and row numbers. At the
> moment I am using 'textread' function to read the data and do some
> simple analysis. All my data are numbers except the header lines.
>
> In the code snippet below, I have "%f%f%f%f%f%f%f%f%f%f%f%f ", but in
> case I have more columns, I need to add more "%f"s. I don't like this
> idea. I understand that if the data has fewer columns, then that's
> not a problem. This suggest that I can avoid problems simply by
> having lots of "%f"'s in the beginning. ...

First, how do you know how many columns are in the file for ultimately
using the data?

That information, along w/ repmat() can make for automating the
generation of the format string.

Alternatively, investigate simply reading the whole file and reshape()
and perhaps you don't need the specific number of "%f"-'s at all...

--

Subject: textread

From: dpb

Date: 11 Sep, 2008 14:58:53

Message: 3 of 4

dpb wrote:
> Jong-Hoon Kim wrote:
> ...
>> I have data files that have variable column and row numbers. At the
>> moment I am using 'textread' function to read the data and do some
>> simple analysis. All my data are numbers except the header lines.

> Alternatively, investigate simply reading the whole file and
> reshape() and perhaps you don't need the specific number of "%f"-'s
> at all...

That is, see if

  data = textread( fullfile(expDir,subDir,dataFile(j).name), ...
         '','headerlines',numHeaderLine, ...
         'commentstyle', 'shell' );

doesn't suit...

--

Subject: textread

From: Jong-Hoon Kim

Date: 25 Sep, 2008 15:31:18

Message: 4 of 4

On Sep 11, 10:58=A0am, dpb <n...@non.net> wrote:
> dpb wrote:
> > Jong-Hoon Kim wrote:
> > ...
> >> I have data files that have variable column and row numbers. =A0At the
> >> moment I am using 'textread' function to read the data and do some
> >> simple analysis. =A0All my data are numbers except the header lines.
> > Alternatively, investigate simply reading the whole file and
> > reshape() and perhaps you don't need the specific number of "%f"-'s
> > at all...
>
> That is, see if
>
> =A0 data =3D textread( fullfile(expDir,subDir,dataFile(j).name), ...
> =A0 =A0 =A0 =A0 =A0'','headerlines',numHeaderLine, ...
> =A0 =A0 =A0 =A0 =A0'commentstyle', 'shell' );
>
> doesn't suit...
>
> --

Thanks for your suggestions. I was able to improve a bit of my
codes.

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us