I have a file with a data value and timestamp that I am trying to split in Matlab. This is the format:
-18.151346 Mon Jan 28 11:33:08 2013
I am using the textscan function to try and split it.
data=textscan(fid,'%f%s%s%f%s%n','delimiter','space');
I am trying to split the timestamp into separate columns so that I can just use the time and not the date or year. I had a look at some previous questions which were very similar but for some reason I just can't get it to do what I want. My resulting cell array is in this format.
Column 1 Column 2 Column 3
-18.151346 Mon Jan 28 11:33:08 2013
I am completely new to Matlab so any help would be greatly appreciated. Thanks in advance.
'space'
string as a delimiter, which is illegal in textscan
. Specify it as ' '
instead.'MultipleDelimsAsOne'
flag to 1.The correct syntax should be:
textscan( fid, '%f%s%s%s%s%n', 'delimiter', ' ', 'MultipleDelimsAsOne', 1);
Had you not tried to tinker with the delimiter option, this behavior would've been done properly by default, so just omit all options:
textscan( fid, '%f%s%s%s%s%n');
Also note that you need a flag for each item in the string that is surrounded by spaces. In other words, for a string like this:
-18.151346 Mon Jan 28 11:33:08 2013
the timestamp in string form will be stored in the 5th column of the resulting cell array.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With