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?

3
  • 4
    C.names(ind) gives an element that itself is a "cell"; try C.names{x,1:end-1} Reference mathworks.com/help/matlab/matlab_prog/… Commented Aug 7, 2014 at 19:22
  • Thanks! Simple question, simple answer ;) Commented Aug 7, 2014 at 19:27
  • 1
    Yvon please provide your solution as an answer so we can up-vote it! Commented Feb 7, 2016 at 11:35

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.