how to use fprintf to print strings and words

조회 수: 41 (최근 30일)
Nabil Abdullah
Nabil Abdullah 2017년 3월 15일
댓글: Nabil Abdullah 2017년 3월 15일
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{:});
  댓글 수: 1
Nabil Abdullah
Nabil Abdullah 2017년 3월 15일
Thank you Jan this is exactly what I wanted!

댓글을 달려면 로그인하십시오.

추가 답변 (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