displaying an element in cell array using fprintf

7 ビュー (過去 30 日間)
Jian Gui
Jian Gui 2014 年 6 月 22 日
コメント済み: Star Strider 2014 年 6 月 22 日
Hi all. I am trying to display an element in cell array in one row using fprintf, but when i do it the resultat is different:
information:
my cell array is C:
C =
[1x6 double] [1x5 double] [1x7 double]
and the code i am using is:
for j=1:length(C)
fprintf('concentration is %.d\n',C{j})
fprintf('\n')
end
the result is:
concentration is 45
concentration is 35
concentration is 20
concentration is 15
concentration is 8
concentration is 4
concentration is 2
what i want it to do:
concentration is 45 35 20 15 8 4 2
anyone who can't help me plz.
Thx..

採用された回答

Star Strider
Star Strider 2014 年 6 月 22 日
A few tweaks to your code is all that’s necessary:
C = {randi(50,1,6) randi(50,1,5) randi(50,1,7)}; % Create data
fprintf('\nconcentration is ')
for j=1:length(C)
fprintf(' %d ',C{j})
end
fprintf('\n')
produces:
concentration is 6 25 48 18 30 12 38 13 26 35 45 48 28 7 8 13 43 13
Is that what you want?
  2 件のコメント
Jian Gui
Jian Gui 2014 年 6 月 22 日
That is exactly what I want, thx:)
Star Strider
Star Strider 2014 年 6 月 22 日
My pleasure!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeResizing and Reshaping Matrices についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by