How to truncate the data in a column vector

I am reading in data from a .xlsx file. One of my columns is the current time which is formatted hour:mins and the other column is the data which is formatted dd/mm/yyyy.
I would like to be able to truncate the time column so I only get the hour, then do the same for minutes (obviously I will have to copy the column vector before hand). The same goes for the date column that uses a / delimiter.
What is the best solution for this?
Thanks

1 commentaire

Post a sample of your data (five lines) then show what you want as result

Connectez-vous pour commenter.

Réponses (1)

Try this:
% Create sample data in Darryl's format.
clear d;
for k = 1:5
d{k, 1} = datestr(now, 'HH:MM');
d{k, 2} = datestr(now, 'dd/mm/yyyy');
pause(1);
end
d
% Now we have sample data in the proper format,
% and now we can start.
% Truncate the first column to hours only
for k = 1 : 5
d{k, 1} = datestr(datenum(d{k, 1}), 'HH');
end
d

5 commentaires

Thank you for your reply and code but I'm a little confused with how you created the sample data. Its my fault as I should of provided some of my code. This is how I am creating the sample data:
a = xlsread(xlsx,'E:E');
plot(a)
hold on
b = xlsread(xlsx,'F:F');
plot(b)
hold on
These are the two columns (time, date). My time column look like this:
13:01
13:02
13:03
13:04
13:05
13:06
....
My date column looks like this:
2/11/2013
2/11/2013
2/11/2013
2/11/2013
2/11/2013
......
Image Analyst
Image Analyst le 2 Nov 2013
Well, you still didn't provide your data (your xls file). So I had to create it myself. And if you run my code, you'll see that I made a good guess because my array looks like the two columns you listed above (assuming those are strings), does it not?
Darryl
Darryl le 3 Nov 2013
I do apologise, please find my .xlsx file attached, and yes they are strings.
Image Analyst
Image Analyst le 3 Nov 2013
Column E and F? Why did you read those in? It looks like the data are in columns H and I, isn't it? Please clarify which columns you want, and if it's E and F like you use in your code, what do those numbers mean?
Darryl
Darryl le 4 Nov 2013
Sorry, yes the columns that need reading in are H and I. The code I used above is extracting data from another .xlsx file.
I'll give you a rundown of the columns:
ID number; lat; long; altitude; speed; tracking angle; satellites; time; date;
So columns E and F are in this case speed and tracking angle

Connectez-vous pour commenter.

Catégories

Question posée :

le 2 Nov 2013

Commenté :

le 4 Nov 2013

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by