CSE 1010 - MATLAB - User-Controlled Input and Output - fprintf

  • Thread starter GreenPrint
  • Start date
  • #1
1,196
0
SOLVED

Homework Statement


Very small dimensions-those on the atomic scale-are often measured in angstroms. An angstrom is represented by the symbol ? and corresponds to a length of 10^-10 meter. Create an inches-to-angstroms conversion table as follows for values of inches from 1 to 10:

Use disp to create a title and column heading

Use fprintf to display the numerical information.

Because the length represented in angstroms is so big, represent your result in scientific notation, showing two values after the decimal point. This corresponds to three significant figures (one before and two after the decimal point).

Homework Equations





The Attempt at a Solution


I can't get MATLAB to corporate with me. I thought the series of commands below would be sufficient and produce the results that I was looking for to solve this problem but I got an answer that I wasn't expecting.
==========
format short e
a=1:10;
b=a.*2.54*10^8;
disp('inches to angstroms')
disp('inches angstroms')
table=[a;b];
fprintf('%3.2f %3.2f\n',table)
==========
This is what is returned by MATLAB after inputing these commands
==========
inches to angstroms
inches angstroms
1.00 254000000.00
2.00 508000000.00
3.00 762000000.00
4.00 1016000000.00
5.00 1270000000.00
6.00 1524000000.00
7.00 1778000000.00
8.00 2032000000.00
9.00 2286000000.00
10.00 2540000000.00
==========
is there anyway I can get MATLAB to display the second column in scientific notation with 2 decimal places and one digit before the decimal point?

Thank you very much!
 
Last edited:

Answers and Replies

Related Threads on CSE 1010 - MATLAB - User-Controlled Input and Output - fprintf

  • Last Post
Replies
4
Views
7K
  • Last Post
Replies
2
Views
686
  • Last Post
Replies
1
Views
560
  • Last Post
Replies
1
Views
481
  • Last Post
Replies
3
Views
5K
Replies
4
Views
2K
Replies
5
Views
6K
Replies
1
Views
7K
Replies
4
Views
1K
  • Last Post
Replies
15
Views
2K
Top