概述
>> %MATLAB基本使用方法
>> %常见操作命令和快捷键
>> %clc清空命令窗口
>> %clear清除工作区中的变量
>> %clf清除图形窗口
>> x=-2*pi:0.05:2*pi;
>> y=3*sin(x)-2*cos(x);
>> plot(x,y)
>> clf
>> %disp显示变量
>> disp('极限是:')
极限是:
>> disp(x)
1 至 9 列
-6.2832 -6.2332 -6.1832 -6.1332 -6.0832 -6.0332 -5.9832 -5.9332 -5.8832
10 至 18 列
-5.8332 -5.7832 -5.7332 -5.6832 -5.6332 -5.5832 -5.5332 -5.4832 -5.4332
19 至 27 列
-5.3832 -5.3332 -5.2832 -5.2332 -5.1832 -5.1332 -5.0832 -5.0332 -4.9832
28 至 36 列
-4.9332 -4.8832 -4.8332 -4.7832 -4.7332 -4.6832 -4.6332 -4.5832 -4.5332
37 至 45 列
-4.4832 -4.4332 -4.3832 -4.3332 -4.2832 -4.2332 -4.1832 -4.1332 -4.0832
46 至 54 列
-4.0332 -3.9832 -3.9332 -3.8832 -3.8332 -3.7832 -3.7332 -3.6832 -3.6332
55 至 63 列
-3.5832 -3.5332 -3.4832 -3.4332 -3.3832 -3.3332 -3.2832 -3.2332 -3.1832
64 至 72 列
-3.1332 -3.0832 -3.0332 -2.9832 -2.9332 -2.8832 -2.8332 -2.7832 -2.7332
73 至 81 列
-2.6832 -2.6332 -2.5832 -2.5332 -2.4832 -2.4332 -2.3832 -2.3332 -2.2832
82 至 90 列
-2.2332 -2.1832 -2.1332 -2.0832 -2.0332 -1.9832 -1.9332 -1.8832 -1.8332
91 至 99 列
-1.7832 -1.7332 -1.6832 -1.6332 -1.5832 -1.5332 -1.4832 -1.4332 -1.3832
100 至 108 列
-1.3332 -1.2832 -1.2332 -1.1832 -1.1332 -1.0832 -1.0332 -0.9832 -0.9332
109 至 117 列
-0.8832 -0.8332 -0.7832 -0.7332 -0.6832 -0.6332 -0.5832 -0.5332 -0.4832
118 至 126 列
-0.4332 -0.3832 -0.3332 -0.2832 -0.2332 -0.1832 -0.1332 -0.0832 -0.0332
127 至 135 列
0.0168 0.0668 0.1168 0.1668 0.2168 0.2668 0.3168 0.3668 0.4168
136 至 144 列
0.4668 0.5168 0.5668 0.6168 0.6668 0.7168 0.7668 0.8168 0.8668
145 至 153 列
0.9168 0.9668 1.0168 1.0668 1.1168 1.1668 1.2168 1.2668 1.3168
154 至 162 列
1.3668 1.4168 1.4668 1.5168 1.5668 1.6168 1.6668 1.7168 1.7668
163 至 171 列
1.8168 1.8668 1.9168 1.9668 2.0168 2.0668 2.1168 2.1668 2.2168
172 至 180 列
2.2668 2.3168 2.3668 2.4168 2.4668 2.5168 2.5668 2.6168 2.6668
181 至 189 列
2.7168 2.7668 2.8168 2.8668 2.9168 2.9668 3.0168 3.0668 3.1168
190 至 198 列
3.1668 3.2168 3.2668 3.3168 3.3668 3.4168 3.4668 3.5168 3.5668
199 至 207 列
3.6168 3.6668 3.7168 3.7668 3.8168 3.8668 3.9168 3.9668 4.0168
208 至 216 列
4.0668 4.1168 4.1668 4.2168 4.2668 4.3168 4.3668 4.4168 4.4668
217 至 225 列
4.5168 4.5668 4.6168 4.6668 4.7168 4.7668 4.8168 4.8668 4.9168
226 至 234 列
4.9668 5.0168 5.0668 5.1168 5.1668 5.2168 5.2668 5.3168 5.3668
235 至 243 列
5.4168 5.4668 5.5168 5.5668 5.6168 5.6668 5.7168 5.7668 5.8168
244 至 252 列
5.8668 5.9168 5.9668 6.0168 6.0668 6.1168 6.1668 6.2168 6.2668
>> %hold 图形保持命令
>> %当关掉MATLAB时,定义的变量会被清除
>> %save 保持内存变量
>> bengS
>> save('bengS.mat')
>> %这时在文件夹会产生一个变量文件bengS.mat
>> %load 加载指定文件中的变量
>> load('bengS.mat')
>> %快捷键
>> %Ctrl+p
>> %Ctrl+p调用上一行
>> %Ctrl+f调用下一行
>> %MATLAB默认的数据类型是双精度型
>> x=5.7
x =
5.7000
>> %整数数据类型:有符号整数(int8,int16,int32,int64),无符号整数(uint8,uint16,uint32,uint64)
>> a=uint8(56)
a =
56
>> a=uint8(560)
a =
255
>> %8位最大也就是2^8-1=255
>> a=uint16(560)
a =
560
>> b=int8(-560)
b =
-128
>> %参见C语言中截断
>> b=int16(-560)
b =
-560
>> b=uint16(-560)
b =
0
>>%类型不匹配,输出错误
>> A=uint16(magic(6))
A =
35 1 6 26 19 24
3 32 7 21 23 25
31 9 2 22 27 20
8 28 33 17 10 15
30 5 34 12 14 16
4 36 29 13 18 11
>> %浮点数;单精度浮点数(single)、双精度浮点数(double)
>> B=single(magic(6))
B =
35 1 6 26 19 24
3 32 7 21 23 25
31 9 2 22 27 20
8 28 33 17 10 15
30 5 34 12 14 16
4 36 29 13 18 11
>> %复数
>> sqrt(-1)
ans =
0.0000 + 1.0000i
>> x=5+6i
x =
5.0000 + 6.0000i
>> y=complex(0,1)
y =
0.0000 + 1.0000i
>> xr=real(x)
xr =
5
>> xi=imag(x)
xi =
6
>> xabs=abs(x)
xabs =
7.8102
>> sqrt(25+36)
ans =
7.8102
>> %幅角
>> xa=angle(x)
xa =
0.8761
>> %弧度-->角度
>> 180/pi*xa
ans =
50.1944
>> %角度
>> conj(x)
ans =
5.0000 - 6.0000i
>> xc=conj(x)
xc =
5.0000 - 6.0000i
>> x = 0:0.01:2*pi;
>> y=x+i*x*sin(x);
错误使用 *
内部矩阵维度必须一致。
>> a=[1,2,3];
>> b=[4,5,6];
>> c=a*b
错误使用 *
内部矩阵维度必须一致。
>> c=a.*b
c =
4 10 18
>> %点乘.*
>> y=x+i*x.*sin(x)
y =
1 至 11 列
0 0.0122 0.0288 0.0498 0.0752 0.1050 0.1392 0.1777 0.2206 0.2680 0.3196
12 至 22 列
0.3757 0.4360 0.5008 0.5698 0.6431 0.7208 0.8027 0.8890 0.9794 1.0741 1.1731
23 至 33 列
1.2762 1.3836 1.4951 1.6107 1.7305 1.8544 1.9824 2.1144 2.2504 2.3905 2.5345
34 至 44 列
2.6826 2.8345 2.9903 3.1500 3.3135 3.4809 3.6520 3.8269 4.0055 4.1877 4.3736
45 至 55 列
4.5631 4.7562 4.9528 5.1528 5.3564 5.5633 5.7737 5.9873 6.2043 6.4245 6.6479
56 至 66 列
6.8745 7.1042 7.3370 7.5728 7.8116 8.0533 8.2979 8.5453 8.7955 9.0485 9.3042
67 至 77 列
9.5625 9.8233 10.0867 10.3526 10.6210 10.8916 11.1647 11.4399 11.7174 11.9970 12.2788
78 至 88 列
12.5625 12.8483 13.1359 13.4255 13.7168 14.0099 14.3046 14.6010 14.8989 15.1984 15.4993
89 至 99 列
15.8015 16.1051 16.4099 16.7159 17.0230 17.3311 17.6403 17.9504 18.2613 18.5731 18.8855
100 至 110 列
19.1986 19.5124 19.8266 20.1413 20.4564 20.7718 21.0875 21.4033 21.7193 22.0353 22.3513
111 至 121 列
22.6672 22.9830 23.2985 23.6137 23.9285 24.2429 24.5568 24.8701 25.1828 25.4947 25.8058
122 至 132 列
26.1161 26.4254 26.7337 27.0410 27.3471 27.6519 27.9555 28.2577 28.5585 28.8578 29.1555
133 至 143 列
29.4515 29.7458 30.0383 30.3290 30.6177 30.9044 31.1891 31.4716 31.7519 32.0298 32.3055
144 至 154 列
32.5787 32.8494 33.1175 33.3831 33.6459 33.9059 34.1631 34.4173 34.6686 34.9169 35.1620
155 至 165 列
35.4039 35.6426 35.8780 36.1100 36.3385 36.5636 36.7850 37.0028 37.2169 37.4272 37.6336
166 至 176 列
37.8362 38.0348 38.2294 38.4198 38.6062 38.7883 38.9661 39.1396 39.3087 39.4733 39.6335
177 至 187 列
39.7890 39.9399 40.0862 40.2277 40.3644 40.4962 40.6231 40.7451 40.8620 40.9739 41.0806
188 至 198 列
41.1822 41.2786 41.3696 41.4553 41.5357 41.6106 41.6801 41.7440 41.8024 41.8551 41.9022
199 至 209 列
41.9436 41.9792 42.0091 42.0331 42.0512 42.0635 42.0698 42.0700 42.0643 42.0525 42.0346
210 至 220 列
42.0105 41.9803 41.9438 41.9011 41.8522 41.7969 41.7353 41.6673 41.5930 41.5122 41.4249
221 至 231 列
41.3312 41.2310 41.1243 41.0110 40.8911 40.7646 40.6315 40.4918 40.3455 40.1924 40.0327
232 至 242 列
39.8662 39.6931 39.5132 39.3266 39.1332 38.9330 38.7261 38.5123 38.2918 38.0645 37.8303
243 至 253 列
37.5893 37.3416 37.0870 36.8255 36.5573 36.2822 36.0003 35.7115 35.4160 35.1136 34.8044
254 至 264 列
34.4884 34.1656 33.8361 33.4997 33.1566 32.8067 32.4500 32.0867 31.7166 31.3398 30.9563
265 至 275 列
30.5662 30.1694 29.7660 29.3559 28.9393 28.5161 28.0864 27.6501 27.2074 26.7582 26.3025
276 至 286 列
25.8405 25.3721 24.8973 24.4162 23.9289 23.4353 22.9355 22.4295 21.9174 21.3991 20.8749
287 至 297 列
20.3446 19.8083 19.2661 18.7180 18.1641 17.6044 17.0389 16.4677 15.8909 15.3084 14.7204
298 至 308 列
14.1269 13.5280 12.9236 12.3139 11.6989 11.0787 10.4533 9.8228 9.1873 8.5467 7.9012
309 至 319 列
7.2509 6.5957 5.9358 5.2712 4.6020 3.9283 3.2500 2.5674 1.8804 1.1891 0.4937
320 至 330 列
-0.2059 -0.9095 -1.6172 -2.3287 -3.0440 -3.7632 -4.4860 -5.2123 -5.9423 -6.6756 -7.4123
331 至 341 列
-8.1523 -8.8955 -9.6419 -10.3912 -11.1435 -11.8987 -12.6566 -13.4173 -14.1805 -14.9463 -15.7145
342 至 352 列
-16.4850 -17.2578 -18.0328 -18.8098 -19.5888 -20.3697 -21.1524 -21.9368 -22.7228 -23.5103 -24.2992
353 至 363 列
-25.0895 -25.8810 -26.6736 -27.4673 -28.2619 -29.0573 -29.8535 -30.6503 -31.4476 -32.2454 -33.0435
364 至 374 列
-33.8419 -34.6404 -35.4390 -36.2374 -37.0358 -37.8338 -38.6315 -39.4287 -40.2253 -41.0212 -41.8163
375 至 385 列
-42.6106 -43.4038 -44.1959 -44.9869 -45.7765 -46.5647 -47.3513 -48.1363 -48.9196 -49.7011 -50.4805
386 至 396 列
-51.2579 -52.0332 -52.8062 -53.5767 -54.3448 -55.1103 -55.8731 -56.6331 -57.3901 -58.1442 -58.8950
397 至 407 列
-59.6427 -60.3870 -61.1278 -61.8650 -62.5986 -63.3284 -64.0543 -64.7762 -65.4940 -66.2076 -66.9169
408 至 418 列
-67.6217 -68.3220 -69.0177 -69.7086 -70.3947 -71.0758 -71.7518 -72.4227 -73.0883 -73.7485 -74.4033
419 至 429 列
-75.0525 -75.6959 -76.3336 -76.9654 -77.5912 -78.2109 -78.8243 -79.4315 -80.0323 -80.6265 -81.2142
430 至 440 列
-81.7951 -82.3693 -82.9365 -83.4968 -84.0499 -84.5959 -85.1345 -85.6658 -86.1896 -86.7058 -87.2143
441 至 451 列
-87.7151 -88.2080 -88.6929 -89.1699 -89.6386 -90.0992 -90.5514 -90.9953 -91.4306 -91.8574 -92.2755
452 至 462 列
-92.6848 -93.0854 -93.4770 -93.8596 -94.2331 -94.5974 -94.9525 -95.2983 -95.6347 -95.9615 -96.2788
463 至 473 列
-96.5865 -96.8845 -97.1727 -97.4510 -97.7193 -97.9777 -98.2260 -98.4641 -98.6921 -98.9097 -99.1170
474 至 484 列
-99.3139 -99.5003 -99.6761 -99.8413 -99.9959 -100.1397 -100.2728 -100.3950 -100.5063 -100.6066 -100.6959
485 至 495 列
-100.7742 -100.8413 -100.8973 -100.9420 -100.9755 -100.9976 -101.0084 -101.0078 -100.9957 -100.9721 -100.9370
496 至 506 列
-100.8902 -100.8319 -100.7619 -100.6803 -100.5868 -100.4817 -100.3647 -100.2359 -100.0953 -99.9427 -99.7783
507 至 517 列
-99.6019 -99.4135 -99.2132 -99.0008 -98.7764 -98.5400 -98.2915 -98.0309 -97.7582 -97.4734 -97.1764
518 至 528 列
-96.8674 -96.5461 -96.2128 -95.8672 -95.5095 -95.1396 -94.7576 -94.3633 -93.9569 -93.5384 -93.1076
529 至 539 列
-92.6647 -92.2096 -91.7424 -91.2630 -90.7715 -90.2679 -89.7521 -89.2243 -88.6844 -88.1325 -87.5685
540 至 550 列
-86.9924 -86.4044 -85.8044 -85.1925 -84.5686 -83.9329 -83.2853 -82.6258 -81.9546 -81.2716 -80.5768
551 至 561 列
-79.8704 -79.1523 -78.4226 -77.6813 -76.9285 -76.1642 -75.3884 -74.6013 -73.8028 -72.9931 -72.1720
562 至 572 列
-71.3398 -70.4965 -69.6421 -68.7766 -67.9002 -67.0129 -66.1148 -65.2059 -64.2862 -63.3560 -62.4151
573 至 583 列
-61.4637 -60.5019 -59.5298 -58.5473 -57.5546 -56.5518 -55.5389 -54.5160 -53.4832 -52.4406 -51.3883
584 至 594 列
-50.3263 -49.2547 -48.1736 -47.0832 -45.9834 -44.8744 -43.7563 -42.6292 -41.4931 -40.3482 -39.1946
595 至 605 列
-38.0323 -36.8615 -35.6822 -34.4946 -33.2988 -32.0948 -30.8828 -29.6630 -28.4353 -27.1999 -25.9569
606 至 616 列
-24.7065 -23.4487 -22.1836 -20.9114 -19.6323 -18.3462 -17.0534 -15.7539 -14.4479 -13.1354 -11.8167
617 至 627 列
-10.4919 -9.1610 -7.8242 -6.4816 -5.1334 -3.7797 -2.4205 -1.0561 0.3134 1.6879 3.0672
628 至 629 列
4.4513 5.8399
>> plot(x,y)
>> subplot(2,1,1)
>> %要画两行一列的第一个图
>> subplot(2,1,1)
>> plot(y)
>> title('直角坐标系绘图')
>> subplot(2,1,2)
>> theta=angle(y);
>> rho=abs(y);
>> polar(theta,rho)
>> title('极坐标系绘图')
>> %数据类型转换
>> %num2str将数字转换位字符串
>> %int2str mat2str str2double str3num cell2mat cell2struct cellstr mat2cell num2cell struct2cell
>> a
a =
1 2 3
>> isa(a,'int64')
ans =
0
>> isa(a,'int32')
ans =
0
>> isa(a,'double')
ans =
1
>> str='I love you';
>> isa(str,'str')
ans =
0
>> %数据类型操作函数
>> %isa(x,'type')
>> %判断是否为type指定的类型,是返回1,否则0
>> %cast(x,'type')
>> %设置x的类型为type
>> a
a =
1 2 3
>> aa=cast(a,'uint8')
aa =
1 2 3
>> isa(a,'double')
ans =
1
>> isa(aa,'double')
ans =
0
>> %aa不是double类型的
>> intmax('uint16')
ans =
65535
>> realmax('double')
ans =
1.7977e+308
>> realmin('double')
ans =
2.2251e-308
>> intmax('int8')
ans =
127
>> intmax('int16')
ans =
32767
>> intmax('int32')
ans =
2147483647
>> intmax('int64')
ans =
9223372036854775807
>> %系统预定义的特殊变量
>> %ans pi eps
>> x=0:1:2*pi;
>> sin(x)
ans =
0 0.8415 0.9093 0.1411 -0.7568 -0.9589 -0.2794
>> x
x =
0 1 2 3 4 5 6
>> cos(x)
ans =
1.0000 0.5403 -0.4161 -0.9900 -0.6536 0.2837 0.9602
>> y1=sin(x)
y1 =
0 0.8415 0.9093 0.1411 -0.7568 -0.9589 -0.2794
>> y2=cos(x)
y2 =
1.0000 0.5403 -0.4161 -0.9900 -0.6536 0.2837 0.9602
>> pi
ans =
3.1416
>> %圆周率前50位
>> vpa(pi,50)
ans =
3.1415926535897932384626433832795028841971693993751
>> vpa(pi)
ans =
3.1415926535897932384626433832795
>> vpa(pi,150)
ans =
3.14159265358979323846264338327950288419716939937510582097494459230781640628620899862803482534211706798214808651328230664709384460955058223172535940813
>> vpa(pi,1000)
ans =
3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117067982148086513282306647093844609550582231725359408128481117450284102701938521105559644622948954930381964428810975665933446128475648233786783165271201909145648566923460348610454326648213393607260249141273724587006606315588174881520920962829254091715364367892590360011330530548820466521384146951941511609433057270365759591953092186117381932611793105118548074462379962749567351885752724891227938183011949129833673362440656643086021394946395224737190702179860943702770539217176293176752384674818467669405132000568127145263560827785771342757789609173637178721468440901224953430146549585371050792279689258923542019956112129021960864034418159813629774771309960518707211349999998372978049951059731732816096318595024459455346908302642522308253344685035261931188171010003137838752886587533208381420617177669147303598253490428755468731159562863882353787593751957781857780532171226806613001927876611195909216420199
>> %eps浮点数的精度,MATLAB中的最小数
>> eps
ans =
2.2204e-16
>> inf
ans =
Inf
>> nan
ans =
NaN
>> %nan不定数
>> %inf无穷
>> %数据输出个数
>> %数据输出格式
>> %通过format命令指定
>> %format short long short_e long_e
>> %默认format short
>> %四位小数
>> pi
ans =
3.1416
>> format long
>> pi
ans =
3.141592653589793
>> rand(5)
ans =
0.814723686393179 0.097540404999410 0.157613081677548 0.141886338627215 0.655740699156587
0.905791937075619 0.278498218867048 0.970592781760616 0.421761282626275 0.035711678574190
0.126986816293506 0.546881519204984 0.957166948242946 0.915735525189067 0.849129305868777
0.913375856139019 0.957506835434298 0.485375648722841 0.792207329559554 0.933993247757551
0.632359246225410 0.964888535199277 0.800280468888800 0.959492426392903 0.678735154857773
>> format short
>> rand(5)
ans =
0.7577 0.7060 0.8235 0.4387 0.4898
0.7431 0.0318 0.6948 0.3816 0.4456
0.3922 0.2769 0.3171 0.7655 0.6463
0.6555 0.0462 0.9502 0.7952 0.7094
0.1712 0.0971 0.0344 0.1869 0.7547
最后
以上就是端庄老师为你收集整理的MATLAB基本指令的全部内容,希望文章能够帮你解决MATLAB基本指令所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复