how to use fprintf to print strings and words

38 vues (au cours des 30 derniers jours)
Nabil Abdullah
Nabil Abdullah le 15 Mar 2017
Commenté : Nabil Abdullah le 15 Mar 2017
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

Réponse acceptée

Jan
Jan le 15 Mar 2017
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 commentaire
Nabil Abdullah
Nabil Abdullah le 15 Mar 2017
Thank you Jan this is exactly what I wanted!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Characters and Strings dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by