how to find minimum time format for each row of a cell array?
2 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
Risposta accettata
Azzi Abdelmalek
il 6 Lug 2013
Modificato: Azzi Abdelmalek
il 6 Lug 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 Commenti
Azzi Abdelmalek
il 6 Lug 2013
Modificato: Azzi Abdelmalek
il 6 Lug 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
Più risposte (1)
dpb
il 6 Lug 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...
0 Commenti
Vedere anche
Categorie
Scopri di più su Cell Arrays in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!