未为“cell”定义函数;输入。 - MATLAB错误

发布于 2024-12-24 04:07:00 字数 1430 浏览 3 评论 0 原文

我在使用 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 初学者。

I have a problem with MATLAB that i cant quite fix. It is throwing me an error, stating

??? 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 wrote me this code and i changed the code to run 2 regular expressions instead of one, since the one regular expression seems to copy over both of the strings in the document into one cell array when its supposed to be in two separate cell arrays.

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

It seems to print out the results for the DOMAIN, but not for the START and STOP values, due to the error. It should just simply, print out the Domain number, START and STOP values inside of the fprintf statement.

I am a beginner to MATLAB.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

人│生佛魔见 2024-12-31 04:07:00

您应该查看 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 the regexp function called above.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文