0

時間情報を含む2つのセル配列があります。

次に例を示します。

'2012-05-10'
'2012-05-10'
'2012-05-10'
'2012-05-10'
'2012-05-10'
'2012-05-11'
'2012-05-11'

'19:28:27.000'
'19:28:38.000'
'21:57:31.000'
'21:57:37.000'
'21:57:40.000'
'21:57:43.000'
'21:57:50.000'

私はユニークなように2つの時間情報が必要でした:

'2012-05-10'    '19:28:27.000'
'2012-05-11'    '21:57:40.000'

私もいつかこれを持っています:

'2012-05-10'
'2012-05-10'
'2012-05-10'
'2012-05-10'
'2012-05-10'

'19:26:27.000'
'19:26:38.000'
'21:55:31.000'
'21:57:37.000'
'21:55:40.000'

これを行うにはどうすればよいですか。

4

2 に答える 2

3

uniqueこれは、次の関数を使用して実行できます。

>> dates = {'01-Jan-2001'; '01-Jan-2001'; '01-Jan-2001'; '02-Jan-2001'};
>> times = {'15:52';'16:03';'17:05';'04:13'};
>> [d idx] = unique(dates);
>> t = times(idx);
>> [d t]
ans = 
    '01-Jan-2001'    '17:05'
    '02-Jan-2001'    '04:13'

このメソッドは、各日付に関連付けられた最後の時刻を取得します。初めてつかむ場合は、次の機能を使用できます。

function [d t] = uniqueDates(dates,times)
[d idx] = unique(flipud(dates));
reversed_times = flipud(times);
t = reversed_times(idx);
于 2012-07-16T14:42:18.690 に答える
1

datevec ()を使用して文字列をvecotrsに変換してから、minおよびsec情報を削除し、datestr()を使用して単一の文字列に変換し直してから、unique()を使用します。

これが例ですが、私はそれをテストしていません:

dates = ['2012-05-10'
'2012-05-10'
'2012-05-10'
'2012-05-10'
'2012-05-10'
'2012-05-11'
'2012-05-11']

times = ['19:28:27.000'
'19:28:38.000'
'21:57:31.000'
'21:57:37.000'
'21:57:40.000'
'21:57:43.000'
'21:57:50.000']

%this bit might not work, if not just do it with a for loop. It is constructing a vecotr of spaces.
spaces = zeros(size(times,1), 1);
spaces(:) = " ";

%Concatenate the date and time strings with a space character between them.
DateVectors = datevec([dates, spaces, times]);
%discard min and sec
DateVectors(:, 5:6) = 0;
%convert back to strings
DateStrings = datestr(DateVectors);
%find unique values
unique(DateStrings)
于 2012-07-16T14:35:00.220 に答える