Date: May 2, 2014 12:36 AM
Author: Derek Goring
Subject: Re: Data Import/Read Question

On Friday, May 2, 2014 1:37:09 PM UTC+12, cabrego  wrote:
> TideMan <mulgor@gmail.com> wrote in message <ce0a938c-df67-402c-86a7-86db6f5e5347@googlegroups.com>...
>

> > On Friday, May 2, 2014 10:06:08 AM UTC+12, cabrego wrote:
>
> > > TideMan <mulgor@gmail.com> wrote in message <bbe48d4f-8e19-4191-b85d-1e7418aee3a8@googlegroups.com>...
>
> > >
>
> > > > On Friday, May 2, 2014 7:22:53 AM UTC+12, cabrego wrote:
>
> > >
>
> > > > > TideMan <mulgor@gmail.com> wrote in message <1c180e8a-f08f-4b14-afd9-2012ddf8985e@googlegroups.com>...
>
> > >
>
> > > > >
>
> > >
>
> > > > > > On Thursday, May 1, 2014 6:59:09 AM UTC+12, cabrego wrote:
>
> > >
>
> > > > >
>
> > >
>
> > > > > > > I've done several variations of batch file imports but this file format has thrown me for a loop. Any tips on how to attack this?
>
> > >
>
> > > > >
>
> > >
>
> > > > > > >
>
> > >
>
> > > > >
>
> > >
>
> > > > > > >
>
> > >
>
> > > > >
>
> > >
>
> > > > > > >
>
> > >
>
> > > > >
>
> > >
>
> > > > > > > header
>
> > >
>
> > > > >
>
> > >
>
> > > > > > >
>
> > >
>
> > > > >
>
> > >
>
> > > > > > > string1: val1, string2: string3, string4: val2 string5 val3 [array1], [ array2], string6
>
> > >
>
> > > > >
>
> > >
>
> > > > > > >
>
> > >
>
> > > > >
>
> > >
>
> > > > > > > .
>
> > >
>
> > > > >
>
> > >
>
> > > > > > >
>
> > >
>
> > > > >
>
> > >
>
> > > > > > > .
>
> > >
>
> > > > >
>
> > >
>
> > > > > > >
>
> > >
>
> > > > >
>
> > >
>
> > > > > > > Footer
>
> > >
>
> > > > >
>
> > >
>
> > > > > >
>
> > >
>
> > > > >
>
> > >
>
> > > > > > Here's one way:
>
> > >
>
> > > > >
>
> > >
>
> > > > > > Read it in to a set of cell arrays as strings separated by commas:
>
> > >
>
> > > > >
>
> > >
>
> > > > > > c=textscan(fid,repmat('%s',1,5),...
>
> > >
>
> > > > >
>
> > >
>
> > > > > > 'headerlines',1,...
>
> > >
>
> > > > >
>
> > >
>
> > > > > > 'delimiter',',');
>
> > >
>
> > > > >
>
> > >
>
> > > > > > then parse each cell array.
>
> > >
>
> > > > >
>
> > >
>
> > > > >
>
> > >
>
> > > > >
>
> > >
>
> > > > > I ran this code,
>
> > >
>
> > > > >
>
> > >
>
> > > > >
>
> > >
>
> > > > >
>
> > >
>
> > > > > fmt=repmat('%s',1,5);
>
> > >
>
> > > > >
>
> > >
>
> > > > > Header=textscan(fid,'%s');
>
> > >
>
> > > > >
>
> > >
>
> > > > > Data=textscan(fid,fmt,'headerlines',1,'delimiter',',');
>
> > >
>
> > > > >
>
> > >
>
> > > > >
>
> > >
>
> > > > >
>
> > >
>
> > > > > Header looks fine, but the Data contained 5 empty cells. Any ideas?
>
> > >
>
> > > >
>
> > >
>
> > > > Why did you add the Header= line when you specified 'headerlines',1 in textscan?
>
> > >
>
> > > >
>
> > >
>
> > > > If you're going to do it this way, you have to delete 'headerlines',1 and tell textscan to read only one line into Header, otherwise it will read the whole file into Header.
>
> > >
>
> > > >
>
> > >
>
> > > > Remove Header= line and try again.
>
> > >
>
> > >
>
> > >
>
> > > Thanks for the suggestions. I wrote header that way because eventually I am going to use the import in a loop and will create an array of headers for reference. I tried a couple of variations of your suggestions and didn't achieve the desired result. I am not sure what the problem is.
>
> > >
>
> > >
>
> > >
>
> > > fmt=repmat('%s',1,5);
>
> > >
>
> > > Data=textscan(fid,fmt,'headerlines',1,'delimiter',',');
>
> > >
>
> > >
>
> > >
>
> > > This generated 5 empty cells again.
>
> > >
>
> > >
>
> > >
>
> > > fmt=repmat('%s',1,5);
>
> > >
>
> > > Header=textscan(fid,'%s');
>
> > >
>
> > > Data=textscan(fid,fmt,'delimiter',',');
>
> > >
>
> > >
>
> > >
>
> > > This generated Header as usual but also included Header as the first entry in the Data cell. Other 4 entries were empty.
>
> >
>
> > There must be something you're not telling me............
>
> > I put:
>
> > header
>
> > string1: val1, string2: string3, string4: val2 string5 val3 [array1], [ array2], string6
>
> > Footer
>
> >
>
> > into test.txt, then
>
> > fid=fopen('test.txt','rt');
>
> > c=textscan(fid,repmat('%s',1,5),'headerlines',1,'delimiter',',')
>
> >
>
> > and got:
>
> > c =
>
> >
>
> > {2x1 cell} {2x1 cell} {2x1 cell} {2x1 cell} {2x1 cell}
>
> >
>
> > Of course, the second row is rubbish because it contains the footer.
>
>
>
> Thanks for your help I appreciate it, perhaps I over simplified my description. Here is the real stuff:
>
> Delta: 1, Panel: Aa1, Value: 1 @ 5 [1303 657], [ 1316 673], CLEAR


I don't see why that won't work, but I don't have access to Matlab right now.
Perhaps there is a bum line somewhere in your file that is screwing things up.
You could try reading in just one line like this:
c=textscan(fid,repmat('%s',1,5),1,'headerlines',1,'delimiter',',')