how to use fprintf to print strings and words

210 visualizzazioni (ultimi 30 giorni)
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

Risposta accettata

Jan
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)

Categorie

Scopri di più su Characters and Strings in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by