摘要: 1.while condition action end 2.输入三个正数 n=3;for i=1:n inputnum=input(['enter a positive number[#' num2str(i) ']:']) while inputnum<=0 fprintf('You enter 阅读全文
posted @ 2022-04-21 11:45 无敌小金刚 阅读(612) 评论(0) 推荐(0)
摘要: 1.for的循环绘图 n=2;for i=1:n x=linspace(0,2*pi,20*i); y=sin(x); subplot(1,n,i); plot(x,y,'ko-'); xlabel('x'); ylabel('y'); title('sin plot');end 2.for循环的嵌 阅读全文
posted @ 2022-04-20 21:50 无敌小金刚 阅读(3419) 评论(0) 推荐(0)
摘要: 注意在写语句时,注意空格与缩进 1.if语句 if condition action; end 2.if-else语句 if condition1 action1 else action2 end 3.elseif语句 if condition1 action1 elseif condition2 阅读全文
posted @ 2022-04-20 20:07 无敌小金刚 阅读(1808) 评论(0) 推荐(0)
摘要: 一、数据的保存和读取 将两行四列的矩阵,分成两行,在图中描绘出来; load test.dat test test = 1.3000 1.4000 2.1000 3.6000 2.3000 5.6000 6.2000 4.5000 plot(1:4,test(1,:))>> hold on>> pl 阅读全文
posted @ 2022-04-14 21:37 无敌小金刚 阅读(115) 评论(0) 推荐(0)
摘要: 一、grid on 与 grid off gird on 显示网格 gird off 关闭网格显示 二、legend() 显示图标 legend('Line 1','Line 2') 三、绘制柱状图 bar(1:10,randi([1,10],[1,10])) 四、数据的保存和读取 1.保存数据 m 阅读全文
posted @ 2022-04-14 16:49 无敌小金刚 阅读(279) 评论(0) 推荐(0)
摘要: 一、plot的默认情况 x=2:7;y=[2 5 6 3 6 5];plot(x,y);与plot(x,y,'-');一样; 二、关于hold的问题; 1.hold on与hold off 在两者之间的时候,所有的线条一起显示; x=2:7;y=[2 5 6 3 6 5];hold on; %画布开 阅读全文
posted @ 2022-04-14 11:05 无敌小金刚 阅读(384) 评论(0) 推荐(0)
摘要: 一、fprintf() >> fprintf('%12.3f\n',pi) 一共占12位,小数点后3位 3.142>> fprintf('|%12.3f|\n',pi)| 3.142|>> fprintf('|%12f|\n',pi) 一共有12位,默认后面小数点后有六位| 3.141593|>> 阅读全文
posted @ 2022-04-13 16:49 无敌小金刚 阅读(601) 评论(0) 推荐(0)
摘要: 1.input输入 v=input('Enter a vector: ') 输入的是一个数组Enter a vector: [12 5 6 78] v = 12 5 6 78 2.output输出 1)fprintf() fprintf('the value is %d,for sure!\n',4 阅读全文
posted @ 2022-04-13 16:39 无敌小金刚 阅读(1254) 评论(0) 推荐(0)
摘要: 一、 在创建新脚本时,开始的注释,称为header;作用是当你在命令行窗口输入help + 脚本文件名称的时候,所呈现的内容; 二、注释 %This script calculates the circumference of a circle%计算圆的周长 %圆的半径radius=5;%计算圆的周 阅读全文
posted @ 2022-04-07 17:27 无敌小金刚 阅读(938) 评论(0) 推荐(0)
摘要: 一、矩阵的乘法 M1=randi([1,3],[3,4]) M1 = 3 1 1 2 3 1 3 1 1 2 1 3 M2=randi([1,9],[4,3]) M2 = 4 8 8 9 3 6 1 9 8 6 7 3 M1*M2 ans = 34 50 44 30 61 57 41 44 37 矩 阅读全文
posted @ 2022-04-07 16:04 无敌小金刚 阅读(742) 评论(0) 推荐(0)