matlab知识积累二

本文介绍了MATLAB中的load命令,强调了它在读取ASCII数据文件时的要求。此外,还讲解了syms与sym的区别、inline函数的使用限制和示例,以及cat、norm、max、zeros和sum等基本函数的用法。

load命令

Load命令存放数据文件的目录一般设置为d:\datafileload,导入*.txt格式的数据文件时可以先打开workspace窗口,在这个窗口的顶部有个工具按钮Load data file...,通过这个打开你的filename.txt文件!
LOAD
可以读MAT-file data或者用空格间隔的格式相似的ASCII datamatlabload读取txt的文件,文件中必须是纯粹的数据,不允许有其他的文字说明。txt的数据文件最好是按矩阵形式排列,在读取之后可直接用于程序。
% Load the file to the matrix, M :
M = load('sample_file.txt')

symssym的区别

syms是定义符号变量
sym是将字符或者数字转换为字符
比如
syms x y %就是定了符号变量x y以后x y就可以直接使用了,有他们运算出来的结果也是符号变量
当然上面的也可以x=sym('x'),y=sym('y')
sys('a+b')%就是将a+b转化为符号表达式
两者有不同的使用场合
比如符号变量涉及的个数比较少,但是使用频率比较高,那么就是使用syms
但是如果个数多,但是使用频率比较少则使用sym

 

inline函数

matlab命令窗口、程序或函数中创建局部函数时,可用inline。优点是不必将其储存为一个单独文件。在运用中有几点限制:不能调用另一个inline函数,只能由一个matlab表达式组成,并且只能返回一个变量—显然不允许[u,v]这种形式。因而,任何要求逻辑运算或乘法运算以求得最终结果的场合,都不能应用inline。除了这些限制,在许多情况下使用该函数非常方便。

Inline函数的一般形式为:

FunctionName=inline(‘任何有效的matlab表达式’, p1,p2 ,.) ,其中‘p1,p2 ,…是出现在表达式中的所有变量的名字。

如:(求解F(x)=x^2*cos(a*x)-b ,a,b是标量;x是向量)

在命令窗口输入:

Fofx=inline(‘x .^2*cos(a*x)-b’ , ‘x’,’a’,’b’);

g= Fofx([pi/3 pi/3.5],4,1)

系统输出为:g=-1.5483 -1.7259

 

cat使用方法

 

norm函数

norm(A,'fro')F-范数,norm(A,inf)∞-范数,norm(A,1)1-范数

默认2范数

 

max函数

Return the maximum of a 2-by-3 matrix from each column:

X = [2 8 4; 7 3 9];

max(X,[],1)

ans =

 

     7     8     9

Return the maximum from each row:

max(X,[],2)

ans =

 

     8

     9

Compare each element of X to a scalar:

max(X,5)

ans =

 

     5     8     5

     7     5     9

zeros函数用法

B = zeros(n) returns an n-by-n matrix of zeros. An error message appears if n is not a scalar.

B = zeros(m,n) or B = zeros([m n]) returns an m-by-n matrix of zeros.

B = zeros(m,n,p,...) or B = zeros([m n p ...]) returns an m-by-n-by-p-by-... array of zeros.

sum函数

B = sum(A)
B = sum(A,dim)
B = sum(..., 'double')
B = sum(..., dim,'double')
B = sum(..., 'native')
B = sum(..., dim,'native')

B = sum(A) returns sums along different dimensions of an array. If A is floating point, that is double or single, B is accumulated natively, that is in the same class as A, and B has the same class as A. If A is not floating point, B is accumulated in double and B has class double.

If A is a vector, sum(A) returns the sum of the elements.

If A is a matrix, sum(A) treats the columns of A as vectors, returning a row vector of the sums of each column.

If A is a multidimensional array, sum(A) treats the values along the first non-singleton dimension as vectors, returning an array of row vectors.

B = sum(A,dim) sums along the dimension of A specified by scalar dim. The dim input is an integer value from 1 to N, where N is the number of dimensions in A. Set dim to 1 to compute the sum of each column, 2 to sum rows, etc.

B = sum(..., 'double') and B = sum(..., dim,'double') performs additions in double-precision and return an answer of type double, even if A has data type single or an integer data type. This is the default for integer data types.

B = sum(..., 'native') and B = sum(..., dim,'native') performs additions in the native data type of A and return an answer of the same data type. This is the default for single and double.

If A = int8(1:20) then sum(A) accumulates in double and the result is double(210) while sum(A,'native') accumulates in int8, but overflows and saturates to int8(127).

 

 

乐播投屏是一款简单好用、功能强大的专业投屏软件,支持手机投屏电视、手机投电脑、电脑投电视等多种投屏方式。 多端兼容与跨网投屏:支持手机、平板、电脑等多种设备之间的自由组合投屏,且无需连接 WiFi,通过跨屏技术打破网络限制,扫一扫即可投屏。 广泛的应用支持:支持 10000+APP 投屏,包括综合视频、网盘与浏览器、美韩剧、斗鱼、虎牙等直播平台,还能将央视、湖南卫视等各大卫视的直播内容一键投屏。 高清流畅投屏体验:腾讯独家智能音画调校技术,支持 4K 高清画质、240Hz 超高帧率,低延迟不卡顿,能为用户提供更高清、流畅的视觉享受。 会议办公功能强大:拥有全球唯一的 “超级投屏空间”,扫码即投,无需安装。支持多人共享投屏、远程协作批注,PPT、Excel、视频等文件都能流畅展示,还具备企业级安全加密,保障会议资料不泄露。 多人互动功能:支持多人投屏,邀请好友加入投屏互动,远程也可加入。同时具备一屏多显、语音互动功能,支持多人连麦,实时语音交流。 文件支持全面:支持 PPT、PDF、Word、Excel 等办公文件,以及视频、图片等多种类型文件的投屏,还支持网盘直投,无需下载和转格式。 特色功能丰富:投屏时可同步录制投屏画面,部分版本还支持通过触控屏或电视端外接鼠标反控电脑,以及在投屏过程中用画笔实时标注等功能。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值