フィルターのクリア

find a string from a cell array

6 ビュー (過去 30 日間)
Elysi Cochin
Elysi Cochin 2016 年 12 月 21 日
コメント済み: Elysi Cochin 2016 年 12 月 22 日
I have a cell array of dates as
'Mon 22-08-2016'
'Mon 22-08-2016'
'Mon 22-08-2016'
'Tue 23-08-2016'
'Tue 23-08-2016'
'Tue 23-08-2016'
'Tue 23-08-2016'
if i enter a date as, '23-08-2016', i want to get the first row with that date....

採用された回答

José-Luis
José-Luis 2016 年 12 月 21 日
a = {'Mon 22-08-2016'
'Mon 22-08-2016'
'Mon 22-08-2016'
'Tue 23-08-2016'
'Tue 23-08-2016'
'Tue 23-08-2016'
'Tue 23-08-2016'}
idx = find(cellfun(@(x) ~isempty(x),strfind(a,'23-08-2016')),1,'first')

その他の回答 (1 件)

Guillaume
Guillaume 2016 年 12 月 21 日
Use a more useful date format, such as datetime
%your inputs:
dates = {'Mon 22-08-2016'
'Mon 22-08-2016'
'Mon 22-08-2016'
'Tue 23-08-2016'
'Tue 23-08-2016'
'Tue 23-08-2016'
'Tue 23-08-2016'};
searchdate = '23-08-2016';
%convert to useful format:
ddates = datetime(dates, 'InputFormat', 'eee dd-MM-yyyy');
dsearchdate = datetime(searchdate, 'InputFormat', dd-MM-yyyy');
find(ddates == dsearchdate, 1) %find first row where dates match
%to display the datetimes with other formats (display won't affect the search
%even if each datetime uses a different format:
ddates.Format = 'eee dd-MM-yyyy'
dsearchdate.Format = 'dd-MM-yyyy'
  1 件のコメント
Elysi Cochin
Elysi Cochin 2016 年 12 月 22 日
thank you all

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeMATLAB についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by