MATLAB Answers

Richard
2

fprintf cell array?

Asked by Richard
on 23 Jan 2017
Latest activity Commented on by Mbikayi Agostinho on 3 Jul 2017
Is there a more elegant way to do this, so you don't have to write every separate cell array index?
fprintf(fidw,[repmat('%s,',1,25) '%s\n'] ... ,sHeads{1},sHeads{2},sHeads{3},sHeads{4},sHeads{5},sHeads{6},sHeads{7},sHeads{8},sHeads{9},sHeads{10},sHeads{11},sHeads{12} ... ,sHeads{13},sHeads{14},sHeads{15}

  0 Comments

Sign in to comment.

Products

1 Answer

Star Strider
Answer by Star Strider
on 23 Jan 2017
 Accepted Answer

See if this does what you want:
cstr = {'The' 'quick' 'brown' 'fox'};
fprintf(1, '%s - ', cstr{:})
fprintf(1, '\n')
writes to the Command Window:
The - quick - brown - fox -

  3 Comments

Richard
on 23 Jan 2017
Thanks Star Strider!!! The ":" was the key that I needed. I like this: fprintf( fidw, [repmat('%s,',1,25) '%s\n'], sHeads{:} );
Star Strider
on 23 Jan 2017
My pleasure!
Thank you! This helped me on my final project

Sign in to comment.