clear; clc; close ; format ; all

advertisement
clear; clc; close all; format shortg;
%Today is all about display
%Two main commands, disp() and fprintf()
%disp can either display a variable or a string of text
x = 1; y = [1:5];
disp(x);
disp('y = '); disp(y);
disp('Hello World')
%fprintf can display numbers and text at the same time
fprintf('x = %f',x)
fprintf('y = '); fprintf(' %f ',y);
fprintf('\n pi = %.2f',pi)
fprintf('\n pi = %.5f',pi)
a = 1/2; b = -3;
fprintf('\n a = %g, b = %g',a,b)
%As seen above fprintf has a lot of formatting options
%For more detail read pages 101-103 and 105-109
%Problem 24
%use the fprintf command to write out the polynomial
%all coefficients to two decimal places
%Problems 10, 17, and 24, I will be grading on how your output looks.
1
y =
1
2
3
4
Hello World
x = 1.000000y = 1.000000
pi = 3.14
pi = 3.14159
a = 0.5, b = -3
Published with MATLAB® R2014a
1
5
2.000000
3.000000
4.000000
5.000000
Download