Identify postion in a date vector
조회 수: 1 (최근 30일)
이전 댓글 표시
Hiii,
I am trying to identify the index of the day and month in a date string.
I used datevec and now I have an array with date strings like this:
x= [09-12-2014 07:45
09-12-2014 08:00
09-12-2014 08:15
09-12-2014 08:30]
I want to identify the position of the day and month but I am not being able to do so..
Can anyone help?
Inês
댓글 수: 0
채택된 답변
Star Strider
2015년 5월 21일
Actually, you used datestr not datevec although datevec would make your task much easier.
This works:
x= ['09-12-2014 07:45'
'09-12-2014 08:00'
'09-12-2014 08:15'
'09-12-2014 08:30'];
[day, mon] = strread(x', '%2d-%2d-%-*4d %*2d:%*2d');
댓글 수: 2
Star Strider
2015년 5월 23일
My pleasure!
This may be a bit more than you asked for, but this is how I would do it (using the listbox and msgbox functions because I like the GUI dialogue functions):
x= ['08-11-2014 07:45'
'10-12-2014 08:00'
'09-12-2014 08:15'
'09-12-2014 08:30'];
Y= [2
5
6
7];
[dateidx,v] = listdlg('PromptString','Select a date', 'SelectionMode', 'Single', 'ListString',x);
msgbox(sprintf('The value corresponding to %s is %0.2f',x(dateidx,:),Y(dateidx)), 'Result');
추가 답변 (0개)
참고 항목
카테고리
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!