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}

 채택된 답변

Star Strider
Star Strider 2017년 1월 23일

11 개 추천

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

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

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Ali Öztürk
Ali Öztürk 2021년 6월 20일

1 개 추천

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

Martijn Van Hasselt
Martijn Van Hasselt 2024년 5월 30일
Exactly what I was looking for -- thank you!
Alireza
Alireza 2024년 10월 1일
God bless you brother, you solved my problem.

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기

제품

태그

질문:

2017년 1월 23일

댓글:

2024년 10월 1일

Community Treasure Hunt

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

Start Hunting!

Translated by