未为“cell”定义函数;输入。 - MATLAB错误
我在使用 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 初学者。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您应该查看 regexp 的返回类型。
在对
fprintf
的调用中,您声明输入是一个整数。这与上面调用的regexp
函数的输出相矛盾。You should have a look at the return type of regexp.
In your call to
fprintf
you state that the input is an integer. This contradicts with the output of theregexp
function called above.