how to find minimum time format for each row of a cell array?
2 次查看(过去 30 天)
显示 更早的评论
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 .
0 个评论
采纳的回答
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
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
更多回答(1 个)
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...
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Cell Arrays 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!