清空环境变量及命令:
clear all
clc
MATLAB编程习惯与风格:
两个%%+空格可以进入cell mode 模式、publish使用、可以自动生成目录,一定要加空格
x_coordinate = rand(1,10);%10个随机x值
y_coordinate = rand(1,10);%10个随机y值,均在0~1之间
figure
plot(x_coordinate,y_coordinate,’-*’)%根据坐标产出实线图像
如何publish:不同的版本publish不一样,形成文件以后点击目录就可以看到对应的内容。
MATLAB程序调试: 学会看错误信息并分析出错原因
1、Subscript indices must eirher be real positive integers or logicals.
A = [1 2 3 4 5];
A(0)%MATLAB所有矩阵、行向量都是以1开始的,0不存在
A(3.5)
A(-2)%Index exceeds matrix dimensions.
2、Undefined function or variable ‘B’.
B
3、 Inner matrix dimensions must agree.
A = [1 2 3 4 5];
B = [1 2 3];
A *B%不符合两矩阵相乘条件
4、 Function definitions are not permitted at the prompt or in scripts.
function c = add(a,b)
c = a + b;%直接引用函数但是没有编写函数文件
5、 Index out of bounds because numel(A)=5.
A = [1 2 3 4 5];
A(6)%A超过只有5个元素,此命令超出边界
6、In an assignment A(I) = B, the number of elements in B and I must be the same.
A(3) = B;%b是矩阵,A(3)是一个元素,不满足赋值元素的条件
7、Expression or statement is incorrect–possibly unbalanced (, {, or [.
mean(A(1:3)%括号不平衡
8、Too many input arguments.
mean(A,1,2)%输入参数过多
9、循环体的调试:断点调试左边一点,就有了断点,加了断点以后RUN,会有指标指向对应代码;此时在WORKSPACE可以看到各项参数的值,然后SETUP,最后会弹出错误的窗口,这时候再对对应的代码进行修改和测试。
a = 1:100;
b = [];
for i =1:21
%原来i是i=1:21 想找到循环的错误爆发点 怎么调试技巧i,i=21:
DAY6 MATLAB学习笔记—编程技巧、 通过命令和工具调试matlab以及错误分析、M文件和matlab程序性能分析
最新推荐文章于 2021-06-21 21:23:04 发布