























Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
An introduction to MATLAB programming, covering the basics of algorithms, scripts, and functions. It explains how to take user input, perform calculations, and display results using MATLAB's input and output functions. The document also introduces formatted output using fprintf and discusses the differences between scripts and functions.
Typology: Lecture notes
1 / 31
This page cannot be seen from the preview
Don't miss anything!
























Introduction to MATLAB Programming
1 >>radius =input('Enter the radius:');
1 >>radius =input('Enter the radius:');
1 >> letter=input('Enter a char:','s')
1 >> disp('Hello World') 2 Hello World 3 >> disp(4ˆ2) 4 16
1 >> disp('Hello World') 2 Hello World 3 >> disp(4ˆ2) 4 16
1 >> fprintf('The answer is %d. \n',42) 2 The answer is 42.
1 >> x=2; 2 >> fprintf('The square root of %d is %.6f.\n',x,sqrt(x)) 3 The square root of 2 is 1.414214.
1 >> fprintf('The answer is %d. \n',42) 2 The answer is 42.
1 >> x=2; 2 >> fprintf('The square root of %d is %.6f.\n',x,sqrt(x)) 3 The square root of 2 is 1.414214.
1 >> fprintf('The square root of %d is ... %20.6f.\n',x,sqrt(x)) 2 The square root of 2 is 1.414214.
1 >> x = [0, 0.5, 1]; 2 >> y = [x; exp(x)]; 3 >> fprintf('%6.1e %12.4e\n',y); 4 0.0e+00 1.0000e+ 5 5.0e-01 1.6487e+ 6 1.0e+00 2.7183e+
1 >> fprintf('My string is %s! \n','Hello World') 2 My string is Hello World!
Introduction to MATLAB Programming Functions
Introduction to MATLAB Programming Functions
Introduction to MATLAB Programming Functions