MATLAB Script Tutorial
MATLAB Script Tutorial
Script: Commands,
Keywords, and More
MATLAB is a high-performance
programming language and
environment widely used for numerical
computation, visualization, and
programming. MATLAB scripts are files
containing a sequence of MATLAB
commands that can be executed
together to perform specific tasks. This
tutorial covers the essential aspects of
MATLAB scripting, including commands,
keywords, and examples.
MATLAB Script: Commands, Keywords, & More
Basic Commands
clc: Clears the command window.
clear: Removes variables from the workspace.
close: Closes figures.
disp: Displays messages or results.
format: Controls the display format of numeric values (e.g.,
format short, format long).
Mathematical Operations
+, -, *, /, ^: Basic arithmetic operations.
sqrt(x): Computes the square root of x.
log(x): Computes the natural logarithm of x.
exp(x): Computes the exponential of x.
sin(x), cos(x), tan(x): Trigonometric functions.
MATLAB Script: Commands, Keywords, & More
Matrix Operations
zeros(m, n): Creates an m x n matrix of zeros.
ones(m, n): Creates an m x n matrix of ones.
eye(n): Creates an identity matrix of size n.
inv(A): Computes the inverse of matrix A.
det(A): Computes the determinant of matrix A.
size(A): Returns the size of matrix A.
length(A): Returns the length of the largest dimension of A.
Plotting Commands
plot(x, y): Creates a 2D line plot.
scatter(x, y): Creates a scatter plot.
bar(x, y): Creates a bar chart.
histogram(x): Plots a histogram.
xlabel('text'): Adds a label to the x-axis.
ylabel('text'): Adds a label to the y-axis.
title('text'): Adds a title to the plot.
legend('label1', 'label2'): Adds a legend to the plot.
MATLAB Script: Commands, Keywords, & More
Example Function
helpful? Comment
Chetan Shidling
@chetan_shidling_ Save
www.cselectricalandelectronics.com