【发布时间】:2012-01-04 04:58:43
【问题描述】:
我的 MATLAB 有一个问题,我无法完全解决。它给我一个错误,说明
??? Error using ==> fprintf
Function is not defined for 'cell' inputs.
Error in ==> writedata at 93
fprintf(fout, 'INSERT INTO postgres VALUES( %s, %s, %s.\n )', domain, start, stop);
@Florian Brucker 给我写了这段代码,我将代码更改为运行 2 个正则表达式而不是一个,因为一个正则表达式似乎将文档中的两个字符串都复制到一个单元格数组中,而它应该在两个独立的元胞数组。
domain = '';
start = '';
stop = '';
fin = fopen('CathDomainDescriptionFile.txt', 'r');
fout = fopen('output_cath.txt', 'w');
% TODO: Add error check!
while true
line = fgetl(fin); % Get the next line from the file
if ~ischar(line)
% End of file
break;
end
[key, value] = strtok(line); % Split line at the first space
switch key
case 'DOMAIN'
% Store domain
domain = value;
case 'SRANGE'
% two regular expressions since the doing it all in one throws an error
% Index exceeds matrix dimensions.
m = regexp(value, 'START=(\d+)', 'tokens');
m2 = regexp(value, 'STOP=(\d+)', 'tokens');
start = m;
stop = m2;
% Print result
fprintf(fout, 'INSERT INTO postgres VALUES( %s, %s, %s.\n )', domain, start, stop);
end
end
fclose(fin);
fclose(fout);
由于错误,它似乎打印出 DOMAIN 的结果,但没有打印出 START 和 STOP 值的结果。它应该只是简单地打印出fprintf 语句中的域号、START 和 STOP 值。
我是 MATLAB 的初学者。
【问题讨论】: