how to find minimum time format for each row of a cell array?

2 ビュー (過去 30 日間)
saharsahar
saharsahar 2013 年 7 月 6 日
Hi all, I have a 4*21 cell array named all_dis. the elements of this cell array may be empty or a time format value such as '00:00:21' .
I want to get the minimum Time(with its location) on each row of this cell array . Any help is really appreciated .

採用された回答

Azzi Abdelmalek
Azzi Abdelmalek 2013 年 7 月 6 日
編集済み: Azzi Abdelmalek 2013 年 7 月 6 日
all_dis={'00:00:21' '00:00:23' '';'12:00:21' [] '11:00:23' }
a=cellfun(@datenum,all_dis,'un',0)
a(cellfun(@isempty,a))={inf}
b=datestr(min(cell2mat(a)'),'HH:MM:SS')
  3 件のコメント
Azzi Abdelmalek
Azzi Abdelmalek 2013 年 7 月 6 日
編集済み: Azzi Abdelmalek 2013 年 7 月 6 日
all_dis={'00:00:21' '00:00:23' '';'12:00:21' [] '11:00:23' }
a=cellfun(@datenum,all_dis,'un',0)
a(cellfun(@isempty,a))={inf}
[b,idx]=min(cell2mat(a)')
b=datestr(b,'HH:MM:SS')
idx
saharsahar
saharsahar 2013 年 7 月 6 日
Great ! Thank you very Much

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

その他の回答 (1 件)

dpb
dpb 2013 年 7 月 6 日
Make up some short sample data...including an empty cell
Matl
>> tt{:}
ans =
'00:00:21'
ans =
'13:12:10' '00:10:01'
ans =
[]
>> dn=cellfun(@datenum,tt,'uniformoutput',false); % convert to datenums
>> [tmin,tloc]=cellfun(@min,dn,'uniformoutput',false); % find minimum, loc
>> % Display the minimum times in string form to show found 'em
>> cellfun(@(x) datestr(x,'HH:MM:SS'),tmin,'uniformoutput',false)
ans =
'00:00:21' '00:10:01' [0x8 char]
>> % And the locations in the rows
>> tloc{:}
ans =
1
ans =
2
ans =
[]
>>
Salt to suit...

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by