how to use fprintf to print strings and words
210 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Nabil Abdullah
il 15 Mar 2017
Commentato: Nabil Abdullah
il 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
0 Commenti
Risposta accettata
Jan
il 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{:});
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Characters and Strings in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!