issues with fprintf

2 次查看(过去 30 天)
Abra dog
Abra dog 2011-11-1
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
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
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.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Text Data Preparation 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by