MATLAB命令

MATLAB数值计算计算和数据可视化是一个交互式程序。您可以输入它的MATLAB提示符“>>”命令窗口中键入命令。

在本节中,我们将提供常用一般MATLAB命令的列表。

管理会话的命令

MATLAB提供会话管理的各种命令。下表提供了所有这样的命令:

命令 目的/作用
clc 清除命令窗口。
clear 从内存中删除变量。
exist 检查存在的文件或变量。
global 声明变量为全局。
help 搜索帮助主题。
lookfor 搜索帮助关键字条目。
quit 停止MATLAB。
who 列出当前变量。
whos 列出当前变量(长显示)。

使用系统命令

MATLAB提供各种有用的命令与系统工作,在工作区中当前的工作,如保存为一个文件,并加载文件。

它还提供了其他系统相关的活动,如各种命令,显示日期,列出目录中的文件,显示当前目录等。

下表显示了一些常用的系统相关的命令:

命令 目的/作用
cd 改变当前目录。
date 显示当前日期。
delete 删除一个文件。
diary 日记文件记录开/关切换。
dir 列出当前目录中的所有文件。
load 负载工作区从一个文件中的变量。
path 显示搜索路径。
pwd 显示当前目录。
save 保存在一个文件中的工作区变量。
type 显示一个文件的内容。
what 列出所有MATLAB文件在当前目录中。
wklread 读取.wk1电子表格文件。 

输入和输出命令

MATLAB提供了以下输入和输出相关的命令:

命令 作用/目的
disp 显示一个数组或字符串的内容。
fscanf 阅读从文件格式的数据。
format 控制屏幕显示的格式。
fprintf 执行格式化写入到屏幕或文件。
input 显示提示并等待输入。
; 禁止显示网版印刷

fscanf和fprintf命令的行为像C scanf和printf函数。他们支持格式如下代码:

格式代码 目的/作用
%s Format as a string.
%d Format as an integer.
%f Format as a floating web3 value.
%e Format as a floating web3 value in scientific notation.
%g Format in the most compact form: %f or %e.
Insert a new line in the output string.
Insert a tab in the output string.

用于数字显示格式的函数有以下几种形式:

Format函数 最多可显示
format short Four decimal digits (default).
format long 16 decimal digits.
format short e Five digits plus exponent.
format long e 16 digits plus exponents.
format bank Two decimal digits.
format + Positive, negative, or zero.
format rat Rational approximation.
format compact Suppresses some line feeds.
format loose Resets to less compact display mode.

向量,矩阵和阵列命令

下表列出了各种命令用于工作数组,矩阵和向量:

命令 作用/目的
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.

绘图命令

MATLAB提供了大量的命令,绘制图表。下表列出了一些常用的命令绘制:

命令 作用/目的
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.
polar Creates polar plot.
semilogx Creates semilog plot. (logarithmic abscissa).
semilogy Creates semilog plot. (logarithmic ordinate).
stairs Creates stairs plot.
stem Creates stem plot.


联系我们

邮箱 626512443@qq.com
电话 18611320371(微信)
QQ群 235681453

Copyright © 2015-2022

备案号:京ICP备15003423号-3