Select parts of number from a cell of many numbers to put in a variable?
1 次查看(过去 30 天)
显示 更早的评论
Hi.
I have used
[num text raw] = xlsread(filename)
to get access to the cells on a bastardised xml/csv type text file. I can read values from cells using
raw(row,col)
This is fine, however my question is, one of these cells contains the date in format
20140802
I wish to select parts of the number and assign variables for month(08), day(02), year(2014).
How exactly can I achieve this? I can't seem to find an answer to what seems to be an easy problem, help appreciated!
0 个评论
采纳的回答
Ben11
2014-8-12
编辑:Ben11
2014-8-13
The easy way would be:
year = YourDate(1:4)
month = YourDate(5:6)
day = YourDate(7:8)
Then you can convert to digits with str2double for example. Is that what you mean?
9 个评论
Ben11
2014-8-13
When you say "it seems to work but no title is present" do you use something like this:
TitleString = sprintf('Graph Plot at %d:%d on %d/%d/%d',hours,minutes,day,month,year);
... add code for your plot
title(TitleString)
if you don't see any title it might be because matlab does not put it at the right place?
更多回答(1 个)
Azzi Abdelmalek
2014-8-12
a=20140802
b=datevec(datenum(num2str(a),'yyyymmdd'))
b(1) % is the year
b(2) % the month
b(3) % the day
3 个评论
Azzi Abdelmalek
2014-8-12
Ross, If you run my code with my data, there are no errors. You just need to use the same class of data then mine, or use this one
a={20140802 20140803}
b=cellfun(@num2str,a,'un',0) % convert from numeric to string
c=datevec(cellfun(@(x) datenum(x,'yyyymmdd'),b))
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Dates and Time 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!