MATLAB: How to use fprintf to print strings and words

fprintf

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

Best Answer

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{:});