Problem turning array vectors into a table

조회 수: 8 (최근 30일)
William Plummer
William Plummer 2019년 2월 3일
댓글: Star Strider 2019년 2월 4일
Im having problems making a degree conversion table out of my array vectors. My script is able to convert degrees into radians however I want to have 2 columns (Degrees, and Radians,) but i cant line my values under the right columns.
This is all I have so far:
a=input('What is the starting degree?');
b=input('What is the degree increment?');
c=input('What is the ending degree?');
disp('Variable Names'), disp('degrees radians ');
D=(a:b:c);
fprintf('%2.2f\n %2.2f\n',D);
R=deg2rad(D);
C=[D,R];
fprintf('%2.3f\n',C);
Ive tried adding spacing to my last [fprintf] function but that wouldnt line my values up with each other under the proper columns.

답변 (1개)

Star Strider
Star Strider 2019년 2월 3일
You’re not concatenating ‘D’ and ‘R’ correctly to create ‘C’, and your second fprintf statement will only print out one column, not two.
Try this:
a=input('What is the starting degree?');
b=input('What is the degree increment?');
c=input('What is the ending degree?');
disp('Variable Names'), disp(' degrees radians ');
D=(a:b:c);
R=deg2rad(D);
C=[D;R];
fprintf('%8.3f\t%9.3f\n',C);
That should do what you want. I also increased the numeric field widths to accommodate larger numbers and negative numbers without causing problems with the column alignments.
  댓글 수: 2
William Plummer
William Plummer 2019년 2월 4일
Thank you for the help.
Star Strider
Star Strider 2019년 2월 4일
My pleasure.
If my Answer helped you solve your problem, please Accept it!

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

카테고리

Help CenterFile Exchange에서 Historical Contests에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by