Re: time stamp, file length
- From: NZTideMan <mulgor@xxxxxxxxx>
- Date: Tue, 27 Oct 2009 21:03:35 -0700 (PDT)
On Oct 28, 4:47 pm, "AP Pal" <avis...@xxxxxxxxx> wrote:
NZTideMan <mul...@xxxxxxxxx> wrote in message <a667391d-693d-4838-876d-a1a148c43...@xxxxxxxxxxxxxxxxxxxxxxxxxxxx>...
On Oct 27, 4:35?pm, "AP Pal" <avis...@xxxxxxxxx> wrote:
"Pekka Kumpulainen" <pekka.nospam.kumpulai...@xxxxxxxxxxxxx> wrote in message <hc3qt9$la...@xxxxxxxxxxxxxxxxxx>...
NZTideMan <mul...@xxxxxxxxx> wrote in message <08fabd78-88f1-4682-98a9-23f019ca5...@xxxxxxxxxxxxxxxxxxxxxxxxxxxx>...
On Oct 24, 5:27?pm, "AP Pal" <avis...@xxxxxxxxx> wrote:
NZTideMan <mul...@xxxxxxxxx> wrote in message <48966c20-cada-4db6-b021-fa06e3678...@xxxxxxxxxxxxxxxxxxxxxxxxxxxx>...
On Oct 24, 6:56?am, "AP Pal" <avis...@xxxxxxxxx> wrote:
Any ideas , any help?? Anyone?
"AP Pal" <avis...@xxxxxxxxx> wrote in message <hbqash$kp...@xxxxxxxxxxxxxxxxxx>...
I have mutiple files with different length, i need to make them all same length with time stamps , but some data are missing in some files
How do i stretch both files to make it same lenghth assigning 0 or blank to data pts which are missing.
?for example
file 1
10.20pm 23
10.30pm 50
10.40pm 60
10.50 pm 24
file 2
10.20pm 34
10.40pm 30
10.50pm 35
i would want
file 2 to read
10.20pm 34
10.30pm -
10.40pm 30
10.50 pm 35
Any help is highly appreciated
thanks a lot
Please don't top post.
It makes the thread hard to follow.
Put your reply UNDERNEATH.
What have you tried?
How do you think the data could be changed in a file as you propose?
I cannot think of any way this can be done using Matlab.
But perhaps you have something in mind?
If it were me, I'd use Matlab to do it in an entirely different way.
Can you tell me how you would do it?
i am trying this by generating a 3rd file and comparing it by timestamp of file 1 in a for loop. I am running into all kinds of problems. First problem is my file is in .csv and csvread ?reads only nums and disregards the date and time.
First thing you need to do is read the data into Matlab using
textscan. ?It is more flexible than csvread. ?You just tell it that
you are using comma for the delimiter, although the snippet of file
you showed us has space, not comma, as the delimiter. You will need to
sort this out in your head first.
Now you need to read up about datenum because the next step is to
convert those times into Matlab days.
Unfortunately, there could be a problem with the "pm"s. There seems to
be a random space between the time and pm. ?Sometimes it's there, but
other times it's not. ?You will have to think of a way around this.
Once you convert the times into Matlab days, you can figure out if
there is a time missing by using the function diff.
Then, you just insert a line at those points where the interval is
larger than expected.
You can write the file off using fprintf.
Some more tips..
If file1 includes all the time instances you need, you can preallocate the data for new file2 with zeros, same size as the data of file1 (a column vector in this case?).
newd2 = zeros(n,k);
Find where the timestamps of file2 are included in file1
doc intersect
[ts, ia,ib] = intersect(t1,t2);
it will give you the indices you need. You can use either datenums as suggested above, but intersect works with cells of strings too. However it looks for exact match, so the same time with and without space between the time and pm will not match.
Then fill the new data from the original file2 to the rows given by intersect
newd2(ia,:) = oldd2;
Then write the file.
If you need full regularly spaced timestamps and are not sure that file1 includes all. Then you can make the new final timestamps and repeat the stuff given above to both files, comparing to the timestamps you created..
hth
====================================================
date time ? ? ? ? ? ? ?M01 ? ? ? M02 ? ? M03 ? ? M04 ? ? M05 ? ? M06
8/15/2009 0:00 ?5.8 ? ? 7.8 ? ? 7.8 ? ? 7.3 ? ? 0 ? ? ? 7.9
8/15/2009 0:10 ?7.1 ? ? 8.1 ? ? 8.1 ? ? 7.7 ? ? 0 ? ? ? 8.1
8/15/2009 0:20 ?6.8 ? ? 7.4 ? ? 7.6 ? ? 7.1 ? ? 0 ? ? ? 7.3
8/15/2009 0:30 ?5.6 ? ? 6.8 ? ? 7.1 ? ? 6.6 ? ? 0 ? ? ? 6.8
8/15/2009 0:40 ?3.9 ? ? 6.2 ? ? 6.4 ? ? 6.2 ? ? 0 ? ? ? 6.4
8/15/2009 0:50 ?4.6 ? ? 5.5 ? ? 6.1 ? ? 5.8 ? ? 0 ? ? ? 5.6
8/15/2009 1:40 ?7 ? ? ? 7 ? ? ? 7.2 ? ? 6.9 ? ? 0 ? ? ? 6.3
Can you help me to read this .csv file ?properly so i can convert the first column into a string using datenum. csvread ofcourse does not work. With textscan i am lost how to call it , so i do not get errors. The date and time are in same column.
Thanks
====================================================
Why do you keep saying this is a .csv file, when then are no commas?
Step by step, here is what you do (see help textscan for details):
1. Open the file using fopen.
2. Figure out the format. In the snippet you have given us, the
delimiter is space, so you will need to read in the date and time
separately using %s for each, then you have 6 floating point numbers,
so you need a %f for each of those.
3. Specify the delimiter as space
4. Specify there is one header line.
5. Read the data in.
You need to try figuring this out and post your code.
We'll help de-bug it, but don't expect people to write the code for
you.
If you're lucky, someone will do it for you, but it won't be me
because that way, you'll never learn and you'll keep on pestering us.
Mr NZTideman you do not have to be mean!! I have posted the question here as i figured what would take me hours might be a simple problem for experts in matlab.
I am not pestering anybody if you feel that way you do not need to post.
And by the way its a .csv file , the reason there was no comma was due to fact that i copied from excel. i am using dlmread and ignoring the 1st column of of time and date by using
data=dlmread('d:/test.csv', ',', 1, 2);
dlmread is good as i do not need 2 worry about spaces.
I am just stuck on how to read date and time so later i can use datenum to convert into string. And yeah when i use textscan with %F written 11 times ( 5 for date and time and 6 for data ) i get garbage o/p
I would really appreciate if someone can help me with this as i feel this should be a routine precedure
You've gotten yourself into a terrible tizz about my direct approach,
and as a result you didn't read my post carefully enough.
I told you there how to do it.
Go through it step by step and follow the instructions.
Yes, it is a routine procedure but:
Don't use dlmread, use textscan
Don't try to read the date and time using %F, use %s. They are
strings.
.
- References:
- time stamp, file length
- From: AP Pal
- Re: time stamp, file length
- From: AP Pal
- Re: time stamp, file length
- From: NZTideMan
- Re: time stamp, file length
- From: AP Pal
- time stamp, file length
- Prev by Date: PROPT solution verification
- Next by Date: Re: read large text files
- Previous by thread: Re: time stamp, file length
- Next by thread: Legend on Curve Fitting
- Index(es):
Relevant Pages
|