フィルターのクリア

Identify postion in a date vector

1 回表示 (過去 30 日間)
Inês Mendes
Inês Mendes 2015 年 5 月 21 日
コメント済み: Star Strider 2015 年 5 月 23 日
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

採用された回答

Star Strider
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 件のコメント
Inês Mendes
Inês Mendes 2015 年 5 月 23 日
編集済み: Star Strider 2015 年 5 月 23 日
if i have an interface in which a user chooses a day and month, how do i extract only the data from that date?
Imagine I have:
x= ['08-11-2014 07:45'
'10-12-2014 08:00'
'09-12-2014 08:15'
'09-12-2014 08:30'];
and
Y=[2
5
6
7]
If the user choose to study November 8th how do i extract only Y=[2].
Can you help?
Thanks!
Star Strider
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 ExchangeDates and Time についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by