Matlab Error: Function is not defined for 'cell' inputs

馋奶兔 提交于 2019-12-18 09:08:21

问题


fid = fopen('./tickers.tex', 'wt+');
for x = 1 : size(C.names,1) 
    fprintf(fid, '%s & ', C.names(x,1:end-1)); 
    fprintf(fid, '%s \\\\ \t\n', C.names(x,end)); 
end 
fclose(fid);

Why does this give me the error:

Error using fprintf Function is not defined for 'cell' inputs.

While this does work:

fprintf(' %f    ', D{:});

I'm having difficulties understanding basic matlab datatypes. Could anyone provide me with a solution to print the cell array just like the last syntax?


回答1:


Ok from the error and code you have I am assuming C is an array of cells and you want to print some string from each entry of C. Assuming this, your code is incorrect. Try this:

fid = fopen('./tickers.tex', 'wt+');
for x = 1 : size(C,1) 
    fprintf(fid, '%s & ', C{x}.names(1:end-1)); 
    fprintf(fid, '%s \\\\ \t\n', C{x}.names(end)); 
end 
fclose(fid);

Is this what you want? If not please provide more information about C



来源:https://stackoverflow.com/questions/25190168/matlab-error-function-is-not-defined-for-cell-inputs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!