From: Muhlbauer on
Hi,

I have troubles reading a line in a text file using textscan.
Here is the example:

UTC Launch Time (y,m,d,h,m,s): 2008, 10, 28, 03:27:29

I tried several things but the problem is that MATLAB gets confused by the "," delimiters.

I tried for example:

tmp=textscan(fid,'%s %s %s %s %f %f %f %f');

which correctly reads all the stuff including 2008 but stops after that due to the ,.
I only need the 2008 10 and 28 information.
How can I do this correctly? Modifying the text line is not an option for me.
From: Walter Roberson on
Muhlbauer wrote:
> Hi,
> I have troubles reading a line in a text file using textscan.
> Here is the example:
>
> UTC Launch Time (y,m,d,h,m,s): 2008, 10, 28, 03:27:29
>
> I tried several things but the problem is that MATLAB gets confused by
> the "," delimiters.
>
> I tried for example:
>
> tmp=textscan(fid,'%s %s %s %s %f %f %f %f');
>
> which correctly reads all the stuff including 2008 but stops after that
> due to the ,.
> I only need the 2008 10 and 28 information.
> How can I do this correctly? Modifying the text line is not an option
> for me.

>> textscan('UTC Launch Time (y,m,d,h,m,s): 2008, 10, 28,
03:27:29', '%*[^:]: %f %f %f%*s', 'Delimiter', ' ,', 'MultipleDelimsAsOne', 1)
ans =
[2008] [10] [28]
From: dpb on
Muhlbauer wrote:
> Hi,
> I have troubles reading a line in a text file using textscan.
> Here is the example:
>
> UTC Launch Time (y,m,d,h,m,s): 2008, 10, 28, 03:27:29
>
....
> I only need the 2008 10 and 28 information.
....

One way assuming the text doesn't change (which doesn't look like it
should)...

tmp=textscan(fid,'UTC Launch Time (y,m,d,h,m,s): %d %d %*[^\n]');

I don't have textscan() in this version to test, but think that should do...

--
From: Muhlbauer on
dpb <none(a)non.net> wrote in message <hqkvrf$ufj$1(a)news.eternal-september.org>...
> Muhlbauer wrote:
> > Hi,
> > I have troubles reading a line in a text file using textscan.
> > Here is the example:
> >
> > UTC Launch Time (y,m,d,h,m,s): 2008, 10, 28, 03:27:29
> >
> ...
> > I only need the 2008 10 and 28 information.
> ...
>
> One way assuming the text doesn't change (which doesn't look like it
> should)...
>
> tmp=textscan(fid,'UTC Launch Time (y,m,d,h,m,s): %d %d %*[^\n]');
>
> I don't have textscan() in this version to test, but think that should do...
>
> --

Unfortunately, your suggestion doesn't solve the problem. It ignores the text before 2008 and reads 2008 correctly but not what comes after that. The "," delimiter is screwing things up...
From: dpb on
Muhlbauer wrote:
> dpb <none(a)non.net> wrote in message
> <hqkvrf$ufj$1(a)news.eternal-september.org>...
>> Muhlbauer wrote:
....
>> > > UTC Launch Time (y,m,d,h,m,s): 2008, 10, 28, 03:27:29
>> > ...
>> > I only need the 2008 10 and 28 information.
>> ...
>>
>> One way assuming the text doesn't change (which doesn't look like it
>> should)...
>>
>> tmp=textscan(fid,'UTC Launch Time (y,m,d,h,m,s): %d %d %*[^\n]');
>>
....

> Unfortunately, your suggestion doesn't solve the problem. It ignores the
> text before 2008 and reads 2008 correctly but not what comes after that.
> The "," delimiter is screwing things up...

Oh, sorry, I forgotted them...

tmp=textscan(fid,'UTC Launch Time (y,m,d,h,m,s): %d, %d, %*[^\n]');

altho I'd look at Walter's suggestion; it's a little slicker in both
finding the ":" as well as using the ' ,' as delimiters w/ the "multiple
as one" option. Either should work.

Here's one I can do that doesn't rely on textscan...

>> s='UTC Launch Time (y,m,d,h,m,s): 2008, 10, 28, 03:27:29';
>> sscanf(s, 'UTC Launch Time (y,m,d,h,m,s): %d, %d, %*[^\n]')
ans =
2008
10
>>

--