2
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?

BigChief
  • 1,413
  • 4
  • 24
  • 37
  • 4
    `C.names(ind)` gives an element that itself is a "cell"; try `C.names{x,1:end-1}` Reference http://www.mathworks.com/help/matlab/matlab_prog/access-data-in-a-cell-array.html – Yvon Aug 07 '14 at 19:22
  • Thanks! Simple question, simple answer ;) – BigChief Aug 07 '14 at 19:27
  • 1
    Yvon please provide your solution as an answer so we can up-vote it! – Adam893 Feb 07 '16 at 11:35

1 Answers1

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

ASantosRibeiro
  • 1,247
  • 8
  • 15