【发布时间】:2011-01-18 02:22:01
【问题描述】:
好的,我似乎已经解决了大部分问题,我只需要专家的眼光来发现我遇到的错误。
我有一个长度为 [125 X 27] 的文件,我想将其转换为长度为 [144 x 27] 的文件。现在,我想用零替换丢失的文件(时间戳)行。 (理想情况下,每天平均 10 分钟,因此文件长度应为 144)
这是我正在使用的代码:
fid = fopen('test.csv', 'rt');
data = textscan(fid, ['%s' repmat('%f',1,27)], 'HeaderLines', 1, 'Delimiter', ',');
fclose(fid);
%//Make time a datenum of the first column
time = datenum(data{1} , 'mm/dd/yyyy HH:MM')
%//Find the difference in minutes from each row
timeDiff = round(diff(datenum(time)*(24*60)))
%//the rest of the data
data = cell2mat(data(2:28));
newdata=zeros(144,27);
for n=1:length(timeDiff)
if timeDiff(n)==10
newdata(n,:)=data(n,:);
newdata(n+1,:)=data(n+1,:);
else
p=timeDiff(n)/10
n=n+p;
end
end
谁能帮我找出我的for 循环中的错误。我的输出文件似乎遗漏了一些带时间戳的值。
%********************************************** ****************************************************** ****************************************************** *****************************************
谁能帮我找出读取上述文件的uiget??
我正在替换
fid = fopen('test.csv', 'rt');
data = textscan(fid, ['%s' repmat('%f',1,27)], 'HeaderLines', 1, 'Delimiter', ',');
fclose(fid);
有
[c,pathc]=uigetfile({'*.txt'},'选择文件','C:\data');
file=[pathc c];
file= textscan(c, ['%s' repmat('%f',1,27)], 'HeaderLines', 1, 'Delimiter', ',');
它不工作
%
旧问题的新补充
p = 1; %index 到目的地
对于 n = 1:长度(timeDiff)
% 如果 timeDiff(n) == 10
% 新文件(p,:) = 文件(n,:);
% 新文件(p+1,:)=文件(n+1,:);
% p = p + 1;
% 其他
% p = p + (timeDiff(n)/10);
% 结束q=cumsum(timeDiff(n)/10);
如果 q==1
新文件(p,:)=文件(n,:);
p=p+1;
其他
p = p + (timeDiff(n)/10);结束
结束
xlswrite('testnewws11.xls',newfile);
即使使用 cumsum 命令,当我的文件在长时间丢失的中间有 1,2 个时间戳时,此代码也会失败 例子
2009 年 8 月 16 日 0:00 5.34
2009 年 8 月 16 日 0:10 3.23
2009 年 8 月 16 日 0:20 2.23
2009 年 8 月 16 日 0:30 1.23
2009 年 8 月 16 日 0:50 70
2009 年 8 月 16 日 2:00 5.23
2009 年 8 月 16 日 2:20 544
2009 年 8 月 16 日 2:30 42.23
2009 年 8 月 16 日 3:00 71.23
2009 年 8 月 16 日 3:10 3.23
我的输出看起来像
5.34
3.23
2.23
0
0
0
0
0
0
0
0
0
5.23
544.
42.23
0
0
0
3.23
有什么想法吗?
【问题讨论】: