필터 지우기
필터 지우기

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 .

채택된 답변

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 CenterFile Exchange에서 Dates and Time에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by