% 陣列
array1 = [1,2,3,4,5]
array2 = [1 3 5 9 7]
m =[1,2,3; 4,5,6; 7,8,9]
% 建立矩陣
m0 = zeros(3,3)
m1 = ones(3,3)
m2 = rand(3,3)
m3 = randn(3,3)
% 轉置矩陣
m =m'
% 水平串聯和垂直串聯
n = zeros(3,3)
[m,n]
[m;n]
% 矩陣運算
aa*3
a+aa*a
a.*a
a =
1 2
3 4
ans =
3 6
9 12
ans =
2 4
6 8
ans =
7 10
15 22
ans =
1 4
9 16
a = [1,2,3; 4,5,6; 7,7,8]
>> a(1,1)
ans =
1>> a(4,4)=2
a = 123
0456
0778
0000
2
>> a(2:4,1:3)
ans =
4567780
00>> a(3,:)
ans =
7780
m = [0:10:100]
m = 0 10 20 30 40 50 60 70 80 90 100
m = [1,2,3; 4,5,6; 7,8,9]
m = 1 2 3
4 5 6
7 8 9
% 矩陣求和
sum(m)
ans =
12 15 18
sum(m,2)
ans =6
1524
diag(m)
ans =
159
diag(fliplr(m))
ans =
357
% 幻方
disp('----------幻方------------')
m = magic(3)
disp('各行的和:')
sum(m,2)
disp('各列的和:')
sum(m)
disp('對角線的和:')
sum(diag(m))
sum(diag(fliplr(m)))
% 文字和字元
text = 'this is a '
'special'
' date'
text =
'this is a 'special' date'
% 檢視變數型別
whos text
name size bytes class attributes
text
1x24 48
char
% 連線字串
hello = 'how are you ?'
[text, '. ', hello]
ans =
'this is a 'special' date. how are you ?'
% 字元與數字轉換
c = '1'
n = 1
num2str
(n)str2num
(c)
% 條件語句
n = 0.5
n = rand
if n < n
disp('n < .5')
elseif n < .3
disp('n <.3')
else
disp('other')
end
% switch語句
n = 3
switch(n)
case
disp('n = 1 or 2')
case
disp('n is 3,4,5')
otherwise
disp('other case')
end
% for迴圈
fori = 1:5
disp(i)
end
% while迴圈
n = 1
while n < 10
n = n + 1
end
% 格式化
a = [1/3
.1111]
format
short
aformat
long
aformat bank
aformat
short e
aformat rat
aformat hex
aa =
0.3333
0.1111
a = 0.333333333333333
0.111100000000000
a = 0.33
0.11
a = 3.3333e-01
1.1110e-01
a = 1/3
1111/10000
a = 3fd5555555555555 3fbc710cb295e9e2
% 取消輸出
longmatrix =[0:1000];
% 長語句
longstatement = 1+2+3+4
... +5+6+7+8+9
% 二維圖
x = [-2*pi:pi/100:2*pi]
y = sin(x)
plot(x,y)
% 新增注釋
xlabel('x')
ylabel('sin(x)')
title('-2π到2π間的正弦影象')
% 影象都畫在一張圖上
hold on
y = cos(x)
plot(x,y,'g--')
% -------------三維圖-------------
% 生成x,y點集
[x,y] = meshgrid(-10:.5:10)
% 指定函式
z = x.^2 + y
% 繪製三維圖
subplot(2,1,1)
surf(x,y,z)
title('surf繪圖')
subplot(2,1,2)
mesh(x,y,z)
title('mesh繪圖')
>> help stats
statistics and machine learning toolbox
version 11.2 (r2017b) 24-jul-2017
distributions.
parameter estimation.
betafit - beta parameter estimation.
binofit - binomial parameter estimation.
evfit - extreme value parameter estimation.
expfit - exponential parameter estimation.
...
matlab R2017a mex 配置過程
2.開啟matlab,將路徑設定為,c盤中libsvm 3.22的安裝路徑,執行mex setup命令,發現失敗,缺少編譯器。mex setup錯誤使用 mex4.重複執行步驟2,選擇c 編譯器,在matlab命令視窗,執行make命令。mex setup mex 配置為使用 mingw64 com...
matlab R2017b 初始化緩慢的問題
博主安裝了matlab2011a後很久,用到matlab2017b的東西,matlab安裝2017b後更改了預設路徑,初始化要好幾分鐘,所以對初始化慢的問題也修復了一下。會出現以下情況 解決辦法如下 先是更改預設路徑 更改快捷方式,快捷方式屬性,初始化位置更改為你的預設路徑。第二種方法是在matla...
Boost Graph Library 快速入門
boost graph library 快速入門 by 燕飛龍 南亮亮 採用boost中的鄰接鍊錶 adjacency list 實現圖的定義 下面是乙個鄰接鍊錶定義的例子 include 首先定義圖中節點和邊的屬性 struct vertexproperty structedgeproperty ...