【问题标题】:Function is not defined for 'cell' inputs. - MATLAB error没有为“单元”输入定义函数。 - MATLAB 错误
【发布时间】: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 的初学者。

【问题讨论】:

    标签: regex matlab printf token


    【解决方案1】:

    你应该看看regexp的返回类型。

    在您对fprintf 的调用中,您声明输入 是一个整数。这与上面调用的regexp 函数的输出相矛盾。

    【讨论】:

    • 抱歉,这应该被解读为字符串。我已经更新了我的代码。你知道我还有什么地方会出错吗?
    • 您可以使用start = cell2mat(m{1}); 转换为数值,只要您确定m{1} 只包含一个元胞数组即可。
    • 现在声明,??? Index exceeds matrix dimensions.。但不知何故,它保存了 600 个条目而不是 10,000 多个条目。
    • 我想我可能发现了索引矩阵维度的问题。这是因为我试图从中提取的数据中有一个负整数。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-07-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多