In our third lecture about MATLAB syntax we simply overview the 'commands' for managing the work session. Now we discuss all the commands one by one.
Commands for managing the work session:
>> The lists of commonly used general MATLAB commands are:
clc
|
Clears the Command window |
clear
|
Removes all variables from memory. |
clear v1 v2
|
Removes the variables v1 and v2 from memory. |
exist ( ' var ' ) | Determines if a file or variable exists having the name ‘var’. |
quit
|
Stops MATLAB. |
who
|
Lists the variables currently in memory. |
whos
|
Lists the current variables and sizes, and indicates if they have imaginary parts. |
exit
|
Exit MATLAB |
global
|
Declares variables to be global.
|
Searches for a help topic.
|
|
lookfor
|
Searches help entries for a keyword.
|
Commands for Working with the System:
>> MATLAB provides various useful commands for working with the system, like saving the current work in the workspace as a file and loading the file later. It also provides various commands for other system-related activities like, displaying date, listing files in the directory, displaying current directory, The table shows some commonly used system-related commands:
cd
|
Changes current directory.
|
date
|
Displays current date.
|
delete
|
Deletes a file.
|
diary
|
Switches on / off diary file recording.
|
dir
|
Lists all files in current directory.
|
load
|
Loads workspace variables from a file.
|
path
|
Displays search path.
|
pwd
|
Displays current directory.
|
save
|
Saves workspace variables in a file.
|
type
|
Displays contents of a file.
|
what
|
Lists all MATLAB files in the current directory.
|
wklread
|
Reads .wk1 spreadsheet file.
|
Input and Output Commands:
>> Following are the input and output related commands in MATLAB:
disp
|
Displays contents of an array or string.
|
fscanf
|
Read formatted data from a file.
|
format
|
Controls screen-display format.
|
fprintf
|
Performs formatted writes to screen or file.
|
input
|
Displays prompts and waits for input.
|
;
|
Suppresses screen printing.
|
>> This picture show you how 'DISP' command works. Open picture in new window and check the following outputs.
1. The black line shows how to simple display string.
2. The red line shows how to display two scalars on one line.
3. The yellow line simply display the transpose of vector x and y. Note ( ' ) symbol with x' and y' is used to taking transpose.
4. The blue line shows how to display string along with numeric data or stored value.
>> The fscanf and fprintf commands behave like C scanf and printf functions. They support the following format codes:
%s
|
Format as a string.
|
%d
|
Format as an integer.
|
%f
|
Format as a floating point value.
|
%e
|
Format as a floating point value in scientific notation.
|
%g
|
Format in the most compact form: %f or %e.
|
\n
|
Insert a new line in the output string.
|
\t
|
Insert a tab in the output string.
|
>> The format function has the following forms used for numeric display:
format short
|
Display up to Four decimal digits (default).
|
format long
|
Display up to 16 decimal digits.
|
format short e
|
Display up to Five digits plus exponent.
|
format long e
|
Display up to 16 digits plus exponents.
|
format bank
|
Display up to Two decimal digits.
|
format +
|
Display up to Positive, negative, or zero.
|
format rat
|
Display up to Rational approximation.
|
format compact
|
Display up to Suppresses some line feeds.
|
formatloose
|
Display up to Resets to less compact display mode.
|
Vector, Matrix and Array Commands:
>> The following table shows various commands used for working with arrays, matrices and vectors:
cat
|
Concatenates arrays.
|
find
|
Finds indices of nonzero elements.
|
length
|
Computes number of elements.
|
linspace
|
Creates regularly spaced vector.
|
logspace
|
Creates logarithmically spaced vector.
|
max
|
Returns largest element.
|
min
|
Returns smallest element.
|
prod
|
Product of each column.
|
reshape
|
Changes size.
|
size
|
Computes array size.
|
sort
|
Sorts each column.
|
sum
|
Sums each column.
|
eye
|
Creates an identity matrix.
|
ones
|
Creates an array of ones.
|
zeros
|
Creates an array of zeros.
|
cross
|
Computes matrix cross products.
|
dot
|
Computes matrix dot products.
|
det
|
Computes determinant of an array.
|
inv
|
Computes inverse of a matrix.
|
pinv
|
Computes pseudoinverse of a matrix.
|
rank
|
Computes rank of a matrix.
|
rref
|
Computes reduced row echelon form.
|
cell
|
Creates cell array.
|
celldisp
|
Displays cell array.
|
cellplot
|
Displays graphical representation of cell array.
|
num2cell
|
Converts numeric array to cell array.
|
deal
|
Matches input and output lists.
|
iscell
|
Identifies cell array.
|
Plotting Commands:
>> MATLAB provides numerous commands for plotting graphs. The following table shows some of the commonly used commands for plotting:
axis
|
Sets axis limits.
|
fplot
|
Intelligent plotting of functions.
|
grid
|
Displays gridlines.
|
plot
|
Generates xy plot.
|
print
|
Prints plot or saves plot to a file.
|
title
|
Puts text at top of plot.
|
xlabel
|
Adds text label to x-axis.
|
ylabel
|
Adds text label to y-axis.
|
axes
|
Creates axes objects.
|
close
|
Closes the current plot.
|
close all
|
Closes all plots.
|
figure
|
Opens a new figure window.
|
gtext
|
Enables label placement by mouse.
|
hold
|
Freezes current plot.
|
legend
|
Legend placement by mouse.
|
refresh
|
Redraws current figure window.
|
set
|
Specifies properties of objects such as axes.
|
subplot
|
Creates plots in subwindows.
|
text
|
Places string in figure.
|
bar
|
Creates bar chart.
|
loglog
|
Creates log-log plot.
|
ploar
|
Creates polar plot.
|
semilogx
|
Creates semilog plot. (logarithmic abscissa).
|
semilogy
|
Creates semilog plot. (logarithmic ordinate).
|
stairs
|
Creates stairs plot.
|
stem
|
Creates stem plot.
|
0Awesome Comments!