how to use fprintf to print strings and words

218 次查看(过去 30 天)
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{:});

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Characters and Strings 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by