2016-09-25 10 views
1

私は変数timestampのサイズが1x8734です。彼らは、日付のシリアル番号であり、最初の3つの要素は次のようにしていると言う:私はdatestrを使用している場合は、私は適切な形式で日付と時刻を取得することができます日付のシリアル番号を実際の日付に変換する

1.0e+05 * 

    7.3618 7.3620 7.3620 

私の質問には、私のコードでループ形式の日付と時刻を使用する必要があります。最初の日付はAug-04-2015 hh:mm:ssです。私が8月にすべての日付を選ぶ必要があるとしたら、どうやってそれをやりますか?

+0

このタイムスタンプマトリックスを取得する際のMATLABコードを教えてください。 –

答えて

0

あなたが使用することができます。どちらも、次のような結果が得られ

timestamp = 1.0e+05 * [ 7.3618 7.3620 7.3599 7.3620 ]; 
abc = datestr(timestamp); 
temp = abc.'; temp=temp(:).'; 
required = abc(ceil(strfind(temp,'Aug')./11),:); 

timestampを数字として使用し、あらかじめ定義された日付と比較すると、次のようになります。

timestamp = randi(180,10,1)+1.0e+05 * 7.3609; % some arbitrary dates 
starts = datenum('1-Aug-2015'); 
ends = datenum('31-Aug-2015'); 
for k = 1:numel(timestamp) 
    if timestamp(k)>=starts && timestamp(k)<=ends 
     % things to do... 
     disp(datestr(timestamp(k))) 
    end 
end 

そして、あなたはさらに行くとでこれをベクトル化することができます

11-Jul-2015 
09-Jul-2015 
18-May-2015 
29-Oct-2015 
23-Aug-2015 
12-Oct-2015 
20-Aug-2015 
14-Oct-2015 
16-Sep-2015 
05-Oct-2015 
あなたは両方のケースで結果を取得します

::のような日付のランダムなセットのために、

Aug_dates = timestamp>=starts & timestamp<=ends; 
disp(datestr(timestamp(Aug_dates))) 

ので

23-Aug-2015 
20-Aug-2015 
+0

ありがとうございます。これを試してみる – kanachi

0

これを使用して行うことができます。

timestamp = 1.0e+05 * [ 7.3618 7.3620 7.3599 7.3620 ]; 
% I have included another value, i.e. 7.3599, for better understanding. 
% 7.3599 is: 26-Jan-2015 
abc = datestr(timestamp); 

rowsabc = size(abc,1); 
def = cell(rowsabc,1); %Pre-allocation 
for k = 1:rowsabc  %Using it in a loop as you said 
    def{k}= strfind(abc(k,:),'Aug'); % finding which dates include 'Aug' 
end 

required = abc(~cellfun('isempty', def),:); %removing the rows of abc not containing 'Aug' 

または代わりに、あなたが使用してループを回避できます。

>> abc 

abc = 
04-Aug-2015 
24-Aug-2015 
26-Jan-2015 
24-Aug-2015 

>> required 

required = 
04-Aug-2015 
24-Aug-2015 
24-Aug-2015 
+0

多くのありがとう。これを試みます。 – kanachi

関連する問題