From: Braden on
I have several months of hourly data logs collected from meteorological instruments recorded at 1Hz. They are in csv form. I have created a function to open and import the data using importdata. The data now exists at vectors in the Matlab workspace.

I would like to create a function to append the files so I can plot and analyze several hours or days of data. The file names denote the time when the hour log begins - HalKirk1McK_yymmdd_hh.csv. The fileName is currently passed into the workspace when the user selects the first csv file to import. I need a function to look at this name, determine the next hour log to open, and append it to the workspace variables. I appreciate any constructive help people can provide.
From: Walter Roberson on
Braden wrote:
> The file names denote the time
> when the hour log begins - HalKirk1McK_yymmdd_hh.csv. The fileName is
> currently passed into the workspace when the user selects the first csv
> file to import. I need a function to look at this name, determine the
> next hour log to open, and append it to the workspace variables.

curTstampstr = filename(13:21);
curTstamp = dateved(curTstampstr, 'yymmdd_HH');
nextTstamp = curTstamp + [0 0 0 1 0 0]; %one hour later
nextTstampstr = datestr(nextTstamp, 'yymmdd_HH');
nextfilename = ['HalKirk1McK_' nextTstampstr '.csv'];
From: Braden on
Walter Roberson <roberson(a)hushmail.com> wrote in message <huroa8$5ab$1(a)canopus.cc.umanitoba.ca>...
> Braden wrote:
> > The file names denote the time
> > when the hour log begins - HalKirk1McK_yymmdd_hh.csv. The fileName is
> > currently passed into the workspace when the user selects the first csv
> > file to import. I need a function to look at this name, determine the
> > next hour log to open, and append it to the workspace variables.
>
> curTstampstr = filename(13:21);
> curTstamp = datevec(curTstampstr, 'yymmdd_HH');
> nextTstamp = curTstamp + [0 0 0 1 0 0]; %one hour later
> nextTstampstr = datestr(nextTstamp, 'yymmdd_HH');
> nextfilename = ['HalKirk1McK_' nextTstampstr '.csv'];

Thanks Walter - this is a neat way to add the hour which I was not aware of. How does it know which part of the filename is the HalKirk1McK_ and the date string? I also need a bit of direction on the appending process. Any suggestions?
From: Walter Roberson on
Braden wrote:
> Walter Roberson <roberson(a)hushmail.com> wrote in message
> <huroa8$5ab$1(a)canopus.cc.umanitoba.ca>...
>> Braden wrote:
>> > The file names denote the time > when the hour log begins -
>> HalKirk1McK_yymmdd_hh.csv. The fileName is > currently passed into
>> the workspace when the user selects the first csv > file to import. I
>> need a function to look at this name, determine the > next hour log to
>> open, and append it to the workspace variables.
>> curTstampstr = filename(13:21);
>> curTstamp = datevec(curTstampstr, 'yymmdd_HH');
>> nextTstamp = curTstamp + [0 0 0 1 0 0]; %one hour later
>> nextTstampstr = datestr(nextTstamp, 'yymmdd_HH');
>> nextfilename = ['HalKirk1McK_' nextTstampstr '.csv'];

> Thanks Walter - this is a neat way to add the hour which I was not aware
> of. How does it know which part of the filename is the HalKirk1McK_ and
> the date string?

indexing the filename by 13 to 21 cuts out the HalKirk1McK_ and .csv parts,
assuming that those parts are of constant length.

After that, the argument given to datevec tells it how to parse what remains.
y indicates a position that is for years, m for months, d for day number, H
for hour, and the _ is to be taken literally.

> I also need a bit of direction on the appending
> process. Any suggestions?

horzcat() or vertcat() perhaps; consider using cell arrays if you need to be
able to access the data for a particular file as a group.
From: Braden on
Walter Roberson <roberson(a)hushmail.com> wrote in message <huu3v8$el$1(a)canopus.cc.umanitoba.ca>...
> Braden wrote:
> > Walter Roberson <roberson(a)hushmail.com> wrote in message
> > <huroa8$5ab$1(a)canopus.cc.umanitoba.ca>...
> >> Braden wrote:
> >> > The file names denote the time > when the hour log begins -
> >> HalKirk1McK_yymmdd_hh.csv. The fileName is > currently passed into
> >> the workspace when the user selects the first csv > file to import. I
> >> need a function to look at this name, determine the > next hour log to
> >> open, and append it to the workspace variables.
> >> curTstampstr = filename(13:21);
> >> curTstamp = datevec(curTstampstr, 'yymmdd_HH');
> >> nextTstamp = curTstamp + [0 0 0 1 0 0]; %one hour later
> >> nextTstampstr = datestr(nextTstamp, 'yymmdd_HH');
> >> nextfilename = ['HalKirk1McK_' nextTstampstr '.csv'];
>
> > Thanks Walter - this is a neat way to add the hour which I was not aware
> > of. How does it know which part of the filename is the HalKirk1McK_ and
> > the date string?
>
> indexing the filename by 13 to 21 cuts out the HalKirk1McK_ and .csv parts,
> assuming that those parts are of constant length.
>
> After that, the argument given to datevec tells it how to parse what remains.
> y indicates a position that is for years, m for months, d for day number, H
> for hour, and the _ is to be taken literally.
>
> > I also need a bit of direction on the appending
> > process. Any suggestions?
>
> horzcat() or vertcat() perhaps; consider using cell arrays if you need to be
> able to access the data for a particular file as a group.

Hi Walter I appreciate the help.
How would I go about setting up a cell array to store my data?