I'm having a bit of trouble with my fprintf
example :
x = 35
y = column of words
fprintf('%g blah blah blah %s',x,y{:})
fprintf then displays
35 blah blah word1
66 blah blah word2
.
.
.
.
how do i make it so it display
35 blah blah
list of words

3 件のコメント

Fangjun Jiang
Fangjun Jiang 2011 年 11 月 1 日
Give a better example please. Your example is not even accurate!
Abra dog
Abra dog 2011 年 11 月 1 日
example
x = 35
y = bunch of words in a column
I want it to display:
35 blah blah blah
column of words
The code i used is
fprintf(%g blah blah %s',x,y{:}
instead of just showing
35 blah blah
column of words
it shows
35 blah blah
1st of the word in y
66 blah blah
2nd word in y
72 blah blah
3rd word in y
and so on
I hope this is a better example.
Fangjun Jiang
Fangjun Jiang 2011 年 11 月 1 日
You have more data than the '%g' and '%s' specified so '%g' and '%s' will be used repeatedly. Apparently, '%g' won't be the right format for strings.
fprintf('%g blah blah\n',x);
fprintf('%s\n',y{:});

サインインしてコメントする。

 採用された回答

Fangjun Jiang
Fangjun Jiang 2011 年 11 月 1 日

1 投票

doc fprintf or doc sprintf has plenty of examples.

その他の回答 (1 件)

Jan
Jan 2011 年 11 月 1 日

1 投票

You need 2 FPRINTF commands:
fprintf('%g blah blah blah\n', x);
fprintf('%s\n', y{:});

カテゴリ

ヘルプ センター および File ExchangeMatrices and Arrays についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by