fprintf cell array?

54 views (last 30 days)
Richard
Richard on 23 Jan 2017
Commented: Alireza on 1 Oct 2024
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}

Accepted Answer

Star Strider
Star Strider on 23 Jan 2017
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
Star Strider
Star Strider on 23 Jan 2017
My pleasure!
Mbikayi Agostinho
Mbikayi Agostinho on 3 Jul 2017
Thank you! This helped me on my final project

Sign in to comment.

More Answers (1)

Ali Öztürk
Ali Öztürk on 20 Jun 2021
if you use both cell and matrix.
seven={'ali';'hilal'};
sevilen={'hilal';'ali'};
sevgisi=[100;0];
for i=1:size(seven,1)
fprintf('%s (n)in %s (y)e sevgisi %d\n',seven{i},sevilen{i},sevgisi(i));
end
writes to the Command Window:
ali (n)in hilal (y)e sevgisi 100
hilal (n)in ali (y)e sevgisi 0
  2 Comments
Martijn Van Hasselt
Martijn Van Hasselt on 30 May 2024
Exactly what I was looking for -- thank you!
Alireza
Alireza on 1 Oct 2024
God bless you brother, you solved my problem.

Sign in to comment.

Categories

Find more on Resizing and Reshaping Matrices in Help Center and File Exchange

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!