Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/matlab/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/spring-mvc/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Matlab 将日期序列号转换为实际日期_Matlab - Fatal编程技术网

Matlab 将日期序列号转换为实际日期

Matlab 将日期序列号转换为实际日期,matlab,Matlab,我有一个大小为1x8734的变量时间戳。它们是日期序列号,表示前3个元素如下: 1.0e+05 * 7.3618 7.3620 7.3620 如果我使用datestr,我可以获得正确格式的日期和时间 我的问题是:我需要在代码中以循环形式使用这些日期和时间。第一个日期为2015年8月4日hh:mm:ss。假设我需要选择8月份的所有日期,我该怎么做呢?这可以通过以下方式完成: timestamp = 1.0e+05 * [ 7.3618 7.3620 7.3599 7.

我有一个大小为1x8734的变量
时间戳
。它们是日期序列号,表示前3个元素如下:

1.0e+05 *

    7.3618    7.3620    7.3620
如果我使用
datestr
,我可以获得正确格式的日期和时间


我的问题是:我需要在代码中以循环形式使用这些日期和时间。第一个日期为
2015年8月4日hh:mm:ss
。假设我需要选择8月份的所有日期,我该怎么做呢?

这可以通过以下方式完成:

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'
或者,也可以使用以下方法避免循环:

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),:);
两者都给出了以下结果:

>> 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

这可以通过以下方式实现:

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'
或者,也可以使用以下方法避免循环:

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),:);
两者都给出了以下结果:

>> 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

您可以使用
时间戳
作为数字,只需与预定义的日期进行比较,如下所示:

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
在这两种情况下,您都会得到以下结果:

23-Aug-2015
20-Aug-2015

您可以使用
时间戳
作为数字,只需与预定义的日期进行比较,如下所示:

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
在这两种情况下,您都会得到以下结果:

23-Aug-2015
20-Aug-2015

你能分享你的matlab代码吗?你能分享你的matlab代码吗?你能分享你的matlab代码吗?你能分享你的matlab代码吗?谢谢。我会试试的,非常感谢。我试试这个