s*****a 发帖数: 2735 | 1 谢了个小程序,用来读入不规则的data,能够读入,但是会报错。
应该是loop上太菜了(原谅我是新手,真不好意思)
我把文件贴出来,请认识的帮看看,run run。
这个问题困扰很久了,还有自己的方法可能真的有点笨,请指点,万分感谢。
data file:
https://www.dropbox.com/s/83nd46ny7gunyhv/data.csv
test code:
https://www.dropbox.com/s/vvzfw6uhhgkekbd/test.m
————————————————————————————————————-
test code copy:(下边两个方法都出错了,虽然能够正常读入)
%% input 1
fid_t = fopen(...
'C:\**\data.csv', ... % <------------- address
'r');
while ~feof(fid_t)
temp1 = fgetl(fid_t);
temp2 = regexprep(temp1, '"', '');
line = csv2cell(temp2);
if strcmp(line{1}, 'DataType:')
if strcmp(line{2}, 'Net')
O2=line{2};
fgetl(fid_t);
NET=[]
while ~feof(fid_t)
tp1 = fgetl(fid_t);
tp2 = regexprep(tp1, '"', '');
line = csv2cell(tp2);
NET=[NET; line];
if isempty(line)
break;
end
end
end
end
end;
fclose(fid_t);
%%----------------------------------------------------------
%% input 2
fid_t = fopen(...
'C:\**\data.csv', ... % <------------- address
'r');
while ~feof(fid_t)
temp1 = fgetl(fid_t);
temp2 = regexprep(temp1, '"', '');
line = csv2cell(temp2);
if strcmp(line{1}, 'DataType:')
if strcmp(line{2}, 'Net')
O2=line{2};
fgetl(fid_t);
NET={};
if ~isempty(line)
while ~feof(fid_t)
tp1 = fgetl(fid_t);
tp2 = regexprep(tp1, '"', '');
temp_1 = textscan(tp2, '%s%s%s%s%s%s%s%s%s',...
'Delimiter', ',');
temp_2=[temp_1{:}];
NET{end+1}=temp_2;
end
end
end
end
end;
fclose(fid_t); |
|