how to use fprintf to print strings and words

35 ビュー (過去 30 日間)
Nabil Abdullah
Nabil Abdullah 2017 年 3 月 15 日
コメント済み: Nabil Abdullah 2017 年 3 月 15 日
Dear All,
I would like to ask how I would get fprintf to produce the following where A = [{'a'} {'b'} {'c'}], B = [1 2 3],
>> a 1
b 2
c 3
Thank you

採用された回答

Jan
Jan 2017 年 3 月 15 日
A = {'a', 'b','c'}; % A nicer notation
B = [1 2 3];
Either a loop:
for k = 1:length(A)
fprintf('%s %g\n', A{k}, B(k));
end
Or create one cell at first:
C = cat(1, A, num2cell(B));
fprintf('%s %g\n', C{:});
  1 件のコメント
Nabil Abdullah
Nabil Abdullah 2017 年 3 月 15 日
Thank you Jan this is exactly what I wanted!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCharacters and Strings についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by