随笔分类 - MatLab
摘要:1.categorical数组 用数字来代替文本; 脚本中: A=[... 3,1;... 2,3;... 2,1;... 1,3....]Valueset=[1:3];catnames={'青少年','中年','老年'};B=categorical(A,Valueset,catnames,'Ord
阅读全文
摘要:1.创建结构体数组 1)一个一个追加的方式创建,效率较低 packages(1)=struct('item_no',123,'cost',19.99,'price',39.95,'code','g')packages = 包含以下字段的 struct: item_no: 123 cost: 19.9
阅读全文
摘要:结构体由字段和值构成 1.用struct()函数创建 package=struct('item_no',123,'cost',19.9,'price',39.95,'code','g')package = 包含以下字段的 struct: item_no: 123 cost: 19.9000 pric
阅读全文
摘要:1.元胞数组>> {23,'a',1:2:9,"hello"}ans = 1×4 cell 数组 {[23]} {'a'} {1×5 double} {["hello"]}>> [1 4 6 76]ans = 1 4 6 76>> {1 4 6 76}ans = 1×4 cell 数组 {[1]}
阅读全文
摘要:1.strcmp()与isequal() strcmp({'A','B'},{'A','B'}) %数组中的每个元素进行判断 ans = 1×2 logical 数组 1 1 >> isequal({'A','B'},{'A','B'}) %数组整体进行判断ans = logical 1>> str
阅读全文
摘要:加号用于连接字符串 "hello"+"goodbey"ans = "hellogoodbey" 方括号也用于连接字符>> ['hello','goodbey']ans = 'hellogoodbey' strcat() 用于捏合字符,字符串,但是char类型空格不加入,string类型空格会加入>>
阅读全文
摘要:1.class():测试变量类型 Apple_char='Apple'Apple_char = 'Apple'>> class(Apple_char)ans = 'char'>> Apple_string="Appple"Apple_string = "Appple">> class(Apple_s
阅读全文
摘要:一、数据的保存和读取 将两行四列的矩阵,分成两行,在图中描绘出来; 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
阅读全文
摘要:一、grid on 与 grid off gird on 显示网格 gird off 关闭网格显示 二、legend() 显示图标 legend('Line 1','Line 2') 三、绘制柱状图 bar(1:10,randi([1,10],[1,10])) 四、数据的保存和读取 1.保存数据 m
阅读全文
摘要:一、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; %画布开
阅读全文
摘要:一、fprintf() >> fprintf('%12.3f\n',pi) 一共占12位,小数点后3位 3.142>> fprintf('|%12.3f|\n',pi)| 3.142|>> fprintf('|%12f|\n',pi) 一共有12位,默认后面小数点后有六位| 3.141593|>>
阅读全文
摘要: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
阅读全文
摘要:一、 在创建新脚本时,开始的注释,称为header;作用是当你在命令行窗口输入help + 脚本文件名称的时候,所呈现的内容; 二、注释 %This script calculates the circumference of a circle%计算圆的周长 %圆的半径radius=5;%计算圆的周
阅读全文
摘要:一、矩阵的乘法 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 矩
阅读全文
摘要:v=rand(1,5) v = 0.3012 0.4709 0.2305 0.8443 0.1948 >> v>0.5 ans = 1×5 logical 数组 0 0 0 1 0 v(u) ;显示logical类型为真值的元素 ans = 0.8443 >> vec=[5 9 3 4 6 11]
阅读全文
摘要:一、三维向量 N N = 2 2 5 6 3 8 2 4 2 6 8 5 T(:,:,1)=N T = 2 2 5 6 3 8 2 4 2 6 8 5 >> T(:,:,2)=randi([1,9],[3,4]) T(:,:,1) = 2 2 5 6 3 8 2 4 2 6 8 5 T(:,:,2)
阅读全文

浙公网安备 33010602011771号