Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

reading a data file to searches on Date

0 views
Skip to first unread message

John Smith

unread,
Oct 4, 2008, 9:27:01 AM10/4/08
to
Hi,
I wanted to read in a file with the following format

Date number number

where date is a string such as "4-Oct-08" and numbers are floating point.

I want to be able to do some searches (using find) on the Date. How do I read in the file such that I can do the searches on the date ?

Many thanks.

John.

Andres

unread,
Oct 4, 2008, 3:40:04 PM10/4/08
to
"John Smith" <cc20...@yahoo.com> wrote in message <gc7qv5$pv0$1...@fred.mathworks.com>...

Hi John,
use textscan to read in the data, i.e. something like

fname = 'c:\jsmith.txt';
fid = fopen(fname);
A = textscan(fid, '%s %f %f');
fclose(fid);

and if necessary apply one of the date functions (like datevec) to the first element of A (which stores the date strings in a cell array of strings). The respective doc pages will give you more insight into this.
I hope this gets you started.
Regards
Andres

John Smith

unread,
Oct 5, 2008, 10:28:01 AM10/5/08
to
Hi Andres,
Thank you very much.

John

"Andres " <ran...@werb.deNoRs> wrote in message <gc8gqk$49v$1...@fred.mathworks.com>...

John Smith

unread,
Oct 5, 2008, 11:05:02 AM10/5/08
to
Thanks again for your help. I'm still strugling to achieve what I want. I'm not able to read the data and when I can see that I've read all the data into cell arrays.

for example, i see

when I print A, where A=textscan(fid, '%s %f %f');
{1202x1 cell} [1202x1 double] [1202x1 double]

I now want to do something like
IDX = find(A{1} == '05-Sep-08')
it gives me error,


??? Undefined function or method 'eq' for input arguments of type 'cell'.

so I tried
IDX = find(datevec(A{1} == datevec(05-Sep-08'))

??? Error using ==> eq
Matrix dimensions must agree.


appreciate any help

Thank you.

John

"Andres " <ran...@werb.deNoRs> wrote in message <gc8gqk$49v$1...@fred.mathworks.com>...

Andres

unread,
Oct 5, 2008, 12:30:17 PM10/5/08
to
"John Smith" <cc20...@yahoo.com> wrote in message <gcal2u$aci$1...@fred.mathworks.com>...
> [..]

> for example, i see
>
> when I print A, where A=textscan(fid, '%s %f %f');
> {1202x1 cell} [1202x1 double] [1202x1 double]
>
> I now want to do something like
> IDX = find(A{1} == '05-Sep-08')
> it gives me error,
>
>
> ??? Undefined function or method 'eq' for input arguments of type 'cell'.
>
> so I tried
> IDX = find(datevec(A{1} == datevec(05-Sep-08'))
>
> ??? Error using ==> eq
> Matrix dimensions must agree.
>
>
> [..]

Hi John,
don't use "==" a) on strings or b) to compare whole rows, it's meant as a numeric element-by-element operation (type doc eq). Use a string function instead, like strmatch or its relatives - see the doc.
Hth
Andres

John Smith

unread,
Oct 6, 2008, 2:40:22 PM10/6/08
to
Hi Andres,
Thank you very much.

John

"Andres " <ran...@werb.deNoRs> wrote in message <gcaq2p$7lv$1...@fred.mathworks.com>...

0 new messages