Spacing in a heading for a table. (fprintf)

조회 수: 4 (최근 30일)
Thomas
Thomas 2013년 3월 1일
I have this code below
fprintf('\n\tAppNumb \tgender \tgpa \texp \tlines (bonus)');
fprintf('\n%11.0f %11.0f %11.4f %11.4f %11.4f %11.0f', With2');
fprintf('\n')
and this code
fprintf('\n\t\tAppNumb \t\tgender \t\tgpa \t\texp \t\tlines (bonus)');
fprintf('\n%11.0f %11.0f %11.4f %11.4f %11.4f %11.0f', Without2');
fprintf('\n')
As you can see neither of them produces a table with headings that match up to their corresponding column. Is there a better way to set the spacing with fprintf?
thank you for your time.

채택된 답변

Sven
Sven 2013년 3월 1일
편집: Sven 2013년 3월 1일
Hi Thomas, try this:
fprintf('%11s%12s%12s%12s%12s%12s\n', 'AppNumb', 'gender','gpa','exp','lines','(bonus)');
fprintf('%11.0f %11.0f %11.4f %11.4f %11.4f %11.0f\n\n', rand(1,6));
Is that what you're looking for?
  댓글 수: 1
Thomas
Thomas 2013년 3월 1일
That is exactly what I wanted, thank you.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Just for fun에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by