Filter löschen
Filter löschen

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

2 Ansichten (letzte 30 Tage)
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 .

Akzeptierte Antwort

Azzi Abdelmalek
Azzi Abdelmalek am 6 Jul. 2013
Bearbeitet: Azzi Abdelmalek am 6 Jul. 2013
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 Kommentare
Azzi Abdelmalek
Azzi Abdelmalek am 6 Jul. 2013
Bearbeitet: Azzi Abdelmalek am 6 Jul. 2013
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 am 6 Jul. 2013
Great ! Thank you very Much

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

dpb
dpb am 6 Jul. 2013
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...

Kategorien

Mehr zu Dates and Time finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by