【问题标题】:printing the content of a cell in matlab into a file将matlab中单元格的内容打印到文件中
【发布时间】:2017-03-18 10:22:08
【问题描述】:

我有一个单元格数据结构,我正在尝试将其打印到一个文件中,但我不断收到此错误: 使用 fprintf 时出错 没有为“单元”输入定义函数。

solWT = optimizeCbModel(recon1,'max','one');
fileID = fopen('Q3.txt','w');
grRateWT = solWT.f
C=cell(2,2);
for system = 1:2%length(recon1.subSystems)
    system

    fluxReactions = recon1.rxns(ismember(recon1.subSystems,recon1.subSystems(system)));
    for reaction = 1:length(fluxReactions)
        model =  recon1;
        model.lb(reaction) = 0;
        model.ub(reaction) = 0;

    end
    solKO = optimizeCbModel(model,'max');
    C{system, 1} =  recon1.subSystems(system);
    C{system, 2} = solKO.f / grRateWT;
end
sortedCellArray = sortrows(C,2);
formatSpec = '%s %2.1f\n';
[nrows,ncols] = size(C);
for row = 1:nrows
    fprintf(fileID,formatSpec,sortedCellArray{row,:});
end

我做错了什么

【问题讨论】:

  • 请提供带有示例数据的完整可执行示例。
  • @thewaywewalk 完成
  • 不,recon1 不见了。我们只需要变量C 的内容来帮助你,请考虑一些简单的代码来重现C 的结构——对于这个问题,实际数字并不重要,只关心结构。
  • 我认为 C 的某些元素是元胞数组,例如 c=cell(2,2); d=细胞(1,1); d={5}; c(1)=d;那么如果你使用 fprintf(c{1}) 它会得到那个错误

标签: matlab


【解决方案1】:

试试

fprintf(fileID,formatSpec,sortedCellArray{row,1}, sortedCellArray{row,2})

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-10-22
    • 1970-01-01
    • 2019-12-23
    • 2021-05-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多