I'm trying to list out something in fprintf how do i do it one at a time? Example: fprintf('blahhh blahh %s blahh bahh\n',K) K = text1 text2 I want it to say blahh blahh text1 blahh blahh and then in another row under it blahh blahh text 2 blahh blahh

 채택된 답변

Grzegorz Knor
Grzegorz Knor 2011년 11월 1일

1 개 추천

K = {'text1'; 'text2'};
arrayfun(@(idx)fprintf('blahhh blahh %s blahh bahh\n',K{idx}),1:numel(K))

추가 답변 (1개)

Daniel Shub
Daniel Shub 2011년 11월 1일

3 개 추천

fprintf is vectorized ...
K = {'text1'; 'text2'};
fprintf('blahhh blahh %s blahh bahh\n',K{:})
gives the same results as the accepted answer.

댓글 수: 1

Grzegorz Knor
Grzegorz Knor 2011년 11월 1일
Thanks for the hint. I did not know that it can be done with cell arrays.

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

카테고리

도움말 센터 및 File Exchange에서 Language Support에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by