2016-10-01 77 views
0

AIM: 我需要在Matlab中同步兩個圖的動畫。在matlab中找到積極的calendarDurations

問題: 這兩幅圖的數據已經以可變採樣率獲得。

SOLUTION: 我在持續時間對象(相對於流式傳輸的開始)中轉換了兩個數據集的時間戳。 現在我想在for循環中繪製兩個數據集。 對於每個循環,我想顯示持續時間內持續時間的數據集樣本。

問題: 如何確定特定樣品的持續時間是否已經發生?

代碼示例: 這裏我模擬和排序10個隨機持續時間(d1)和1個隨機消逝時間(et)。我想找出哪些持續時間已過去的時間。

`

% simulate elapsed time 
et = calendarDuration(round(rand(1,6)*10)); 

% simulate data for plot 1 
data_for_plot1 = rand(10,1); 

% simulate durations for the samples in plot1 
d1 = calendarDuration(sortrows(round(rand(10,6)*10))); 

% find index of durations which are before the elapsed time 
is_past = (d1-et)>0; 

% plot the data 
plot(data_for_plot1(is_past)) 

`

ERROR MESSAGE

is_past = (d1-et)>0;

未定義操作符 '>' 類型 'calendarDuration' 的輸入參數。

其他解決方案: 這是我第一次使用持續時間和日期對象,我討厭它的每一點。如果您有其他解決方案,我很樂意聽取他們的意見。 請注意,data1的時間戳以字符串形式出現('yyyy-MM-dd HH:mm:ss.SSS'),data2的時間戳爲雙精度(例如:42.525,42和525 ms)。

謝謝您的幫助

回答

0

可以使用split函數用於此目的。

使用is_past = split((d1-et),'time')> 0;而不是is_past = (d1-et)>0;

+0

謝謝。這解決了它。 –