From: Dev on
Try this:

data1sd = textscan(fid,'%s' );
[sdfiletime] = data1sd{:,1}
p = char(sdfiletime);
sdfileyear = str2double(p(:,1:2))
sdfilemonth = str2double(p(:,3:4))
sdfileday = str2double(p(:,5:6))
From: Jon on
OK, so now that I got that far now I need to get hours, days, and seconds from a vector of
this format '0:3:13.7305'. I have the numbers split into some kind of cell array but I can't for
the life of me figure out how to extract them.

[sdfiletime] = data1sd{4}; which has
sdfiletime =
'0:3:13.7305'
'0:20:12.563'
'0:26:59.1167'
'0:27:28.2257'
'0:30:44.4023'
and then I use [sdsubtime] = regexp(sdfiletime, ':', 'split'); which gives me
sdsubtime =
{1x3 cell}
{1x3 cell}
{1x3 cell}
{1x3 cell}
{1x3 cell}
{1x3 cell}

Now I've tried all sorts of crazy things to get these numbers out. Like:
sdsubtime{1} =
'0' '3' '13.7305'
sdsubtime{2} =
'0' '20' '12.563'
and so on...
but yet if I do sdsubtime{:} I get the same thing as I did with sdsubtime{1}

Both sdhour = str2double(cellfun(@(x) x(1),sdsubtime,'UniformOutput', false)) and
str2double(cellfun(@(x) x(1,1),sdsubtime,'UniformOutput', false)) give me a vector of NaN.

I've tried cell2mat, I've tried variations on indexing... I don't know what else to do here.
From: Walter Roberson on
Jon wrote:

> Both sdhour = str2double(cellfun(@(x) x(1),sdsubtime,'UniformOutput',
> false)) and
> str2double(cellfun(@(x) x(1,1),sdsubtime,'UniformOutput', false)) give
> me a vector of NaN.

You need {1} instead of (1). Also, you can use

cellfun(@(x) str2double(x{1}), sdsubtime)

Vectorizing the str2double() call like you did would possibly be more
efficient, but sometimes clarity is more important than efficiency.
From: Jon on
Thank you! These two strings are the most difficult programming I've ever done. Hah. It might be because I haven't done anything but programming since Friday. My brain is jello. Thanks again.

Walter Roberson <roberson(a)hushmail.com> wrote in message <LDlNn.74437$304.69938(a)newsfe12.iad>...
> Jon wrote:
>
> > Both sdhour = str2double(cellfun(@(x) x(1),sdsubtime,'UniformOutput',
> > false)) and
> > str2double(cellfun(@(x) x(1,1),sdsubtime,'UniformOutput', false)) give
> > me a vector of NaN.
>
> You need {1} instead of (1). Also, you can use
>
> cellfun(@(x) str2double(x{1}), sdsubtime)
>
> Vectorizing the str2double() call like you did would possibly be more
> efficient, but sometimes clarity is more important than efficiency.