FreeMat v4.0 日本語ドキュメント
配列の生成および操作

 

ドキュメント目次

-------------------------------------------------------------------------------------------------
unique 唯一の要素を探す
それぞれが重複しない要素のベクトルを出力します。 
  [構文]
 y = unique(x)
 [y, m, n] = unique(x)
 y = unique(x,'rows') 
 [y, m, n] = unique(x,'rows') 

  [例]

(1) 行の比較(数値)

--> A = randi(1,3*ones(15,3))

A =

2 3 2
2 1 1
2 2 3
2 1 3
2 2 3
2 1 2
1 2 2
1 1 1
3 1 3
2 2 2
1 3 3
1 2 3
3 1 1
3 3 1
2 3 3

--> unique(A,'rows')

ans =

1 1 1
1 2 2
1 2 3
1 3 3
2 1 1
2 1 2
2 1 3
2 2 2
2 2 3
2 3 2
2 3 3
3 1 1
3 1 3
3 3 1

--> [b,m,n] = unique(A,'rows');
--> b

ans =

1 1 1
1 2 2
1 2 3
1 3 3
2 1 1
2 1 2
2 1 3
2 2 2
2 2 3
2 3 2
2 3 3
3 1 1
3 1 3
3 3 1

--> A(m,:)

ans =

1 1 1
1 2 2
1 2 3
1 3 3
2 1 1
2 1 2
2 1 3
2 2 2
2 2 3
2 3 2
2 3 3
3 1 1
3 1 3
3 3 1

--> b(n,:)

ans =

2 3 2
2 1 1
2 2 3
2 1 3
2 2 3
2 1 2
1 2 2
1 1 1
3 1 3
2 2 2
1 3 3
1 2 3
3 1 1
3 3 1
2 3 3


(2) 行の比較(数値)

--> A = randi(1,5*ones(10,1))

A =

5
5
5
3
5
3
4
1
3
2

--> unique(A)

ans =

1
2
3
4
5

--> [b,m,n] = unique(A,'rows');
--> b

ans =

1
2
3
4
5

--> A(m)

ans =

1
2
3
4
5

--> b(n)

ans =

5
5
5
3
5
3
4
1
3
2


(3)セル配列の比較
--> A = {'hi','bye','good','tell','hi','bye'}

A =

['hi'] ['bye'] ['good'] ['tell'] ['hi'] ['bye']

--> unique(A)

ans =

['bye']
['good']
['hi']
['tell']

-------------------------------------------------------------------------------------------------
xnrm2 BLASのnormを計算
 2-normを計算します。
[構文]
 y = xnrm2(A) 

[例]

--> A=randi(zeros(10,1),ones(10,1)*3)

A =

3
1
3
3
1
1
2
2
0
3

--> xnrm2(A)

ans =

6.8557


-------------------------------------------------------------------------------------------------
sort ソート
[構文]
 B = sort(A)
 B = sort(A,dim)
 B = sort(A,dim,mode) 
modeで'ascend'(デフォルト)、'descend' を選択することで、降順
昇順を選択することが可能です。また 
 [B,IX] = sort(A)
[B,IX] = sort(A,dim)
[B,IX] = sort(A,dim,mode)
のように第二出力引数を与えることで変換前のインデックスを得る
ことも可能です。 

[例]

(1)数値のソート
--> A = int32(10*rand(4,3))

A =

8 3 7
5 3 8
6 5 1
7 3 5

--> [B,IX] = sort(A)
B =

5 3 1
6 3 5
7 3 7
8 5 8

IX =

2 1 3
3 2 4
4 4 1
1 3 2

--> [B,IX] = sort(A,2)
B =

3 7 8
3 5 8
1 5 6
3 5 7

IX =

2 3 1
2 1 3
3 2 1
2 3 1

--> [B,IX] = sort(A,1,'descend')
B =

8 5 8
7 3 7
6 3 5
5 3 1

IX =

1 3 2
4 1 1
3 2 4
2 4 3
(2) 文字列もしくはセル配列  
--> a = {'hello','abba','goodbye','jockey','cake'}

a =

['hello'] ['abba'] ['goodbye'] ['jockey'] ['cake']

--> b = sort(a)

b =

['abba'] ['cake'] ['goodbye'] ['hello'] ['jockey']


-------------------------------------------------------------------------------------------------
rcond 

1-normの仮定数を推定します。詳細はLAPACKのXGECONのドキュメントを
参照ください。 

[構文]
 x = rcond(A)


[例]


--> A = rand(30);
--> rcond(A)

ans =

6.6318e-04


仮定数の定義式を用いて計算することもできる。

--> 1/(norm(A,1)*norm(inv(A),1))

ans =

6.5055e-04


------------------------------------------------------------------------------------------------

reshape 配列のサイズを変更
[構文]
 y = reshape(x,d1,d2,...,dn).
 y = reshape(x,[d1,d2,...,dn]).


 [例]

(1) 
--> a = uint8(1:6)

a =

1 2 3 4 5 6

--> reshape(a,2,3)

ans =

1 3 5
2 4 6
(2)
--> a = uint8(1:12)

a =

1 2 3 4 5 6 7 8 9 10 11 12

--> reshape(a,[2,3,2])

ans =

(:,:,1) =

1 3 5
2 4 6

(:,:,2) =

7 9 11
8 10 12
(3) 配列を配列に変換した例
--> a = [1,6,7;3,4,2]

a =

1 6 7
3 4 2

--> reshape(a,3,2)

ans =

1 4
3 7
6 2



-------------------------------------------------------------------------------------------------

zeros 要素が0の配列を作成
[構文]
 y = zeros(d1,d2,...,dn)
 y = zeros(d1,d2,...,dn,classname) 
 y = zeros([d1,d2,...,dn])
 y = zeros([d1,d2,...,dn],classname) 
classnameには、'double', 'single', 'int8', 'uint8',
'int16', 'uint16', 'int32', 'uint32', 'int64', 'uint64',
 'float', 'logical' のいずれかが入ります。

  [例]

(1)

--> zeros(2,3,2)

ans =

(:,:,1) =

0 0 0
0 0 0

(:,:,2) =

0 0 0
0 0 0

--> zeros(1,3)

ans =

0 0 0


(2)

--> zeros([2,6])

ans =

0 0 0 0 0 0
0 0 0 0 0 0

--> zeros([1,3])

ans =

0 0 0


(3)型を指定します。
--> uint16(zeros(3))

ans =

0 0 0
0 0 0
0 0 0

--> zeros(3,'int16')

ans =

0 0 0
0 0 0
0 0 0

------------------------------------------------------------------------------------------------
cell セル配列の作成
空のセル配列を作成します。
[構文]
 y = cell(d1,d2,...,dn)
 y = cell([d1,d2,...,dn]) 

  [例]


--> cell(2,3,2)

ans =

(:,:,1) =

[] [] []
[] [] []

(:,:,2) =

[] [] []
[] [] []

--> cell(1,3)

ans =

[] [] []


2番目の構文を用います。
--> cell([2,6])

ans =

[] [] [] [] [] []
[] [] [] [] [] []

--> cell([1,3])

ans =

[] [] []


-----------------------------------------------------------------------------------------------
ones 要素が1の配列を作成
[構文]
 y = ones(d1,d2,...,dn)
 y = ones([d1,d2,...,dn]) 

yの型は、float型(32-bit 浮動小数点)となります。

 [例]

(1)
--> ones(2,3,2)

ans =

(:,:,1) =

1 1 1
1 1 1

(:,:,2) =

1 1 1
1 1 1

--> ones(1,3)

ans =

1 1 1
(2) 2つ目の構文
--> ones([2,6])

ans =

1 1 1 1 1 1
1 1 1 1 1 1

--> ones([1,3])

ans =

1 1 1
(3) キャストによる型の変更 
--> uint16(ones(3))

ans =

1 1 1
1 1 1
1 1 1

-----------------------------------------------------------------------------------------------
find 否ゼロの要素を探す
[構文]
 y = find(x)
 [r,c] = find(x)
 [r,c,v] = find(x)
 y = find(x,k)
 y = find(x,k,'first')
y = find(x,k,'last')
 rは行(row)で見た時、cは列(column)で見た時のインデックス。
 kは返値の最大要素数。 

  [例]

(1) 論理値の場合

--> a = [1,2,5,2,4];
--> find(a==2)

ans =

2 4


(2) 論理値の場合

--> A = [1,0,3;0,2,1;3,0,0]

A =

1 0 3
0 2 1
3 0 0

--> n = find(A==0)

n =

2
4
6
9

--> A(n) = 5

A =

1 5 3
5 2 1
3 5 5

以下のようにしても可能です。

--> A = [1,0,3;0,2,1;3,0,0]

A =

1 0 3
0 2 1
3 0 0

--> A(A==0) = 5

A =

1 5 3
5 2 1
3 5 5
(3)
--> A = [1,0,3;0,2,1;3,0,0]

A =

1 0 3
0 2 1
3 0 0

--> [r,c] = find(A)
r =

1
3
2
1
2

c =

1
1
2
3
3
(4)
--> [r,c,v] = find(A)
r =

1
3
2
1
2

c =

1
1
2
3
3

v =

1
3
2
3
1


------------------------------------------------------------------------------------------------

num2str 数値を文字列にする
[構文]
 s = num2str(X)
 s = num2str(X, precision) 
 s = num2str(X, format)
precisionは数字を表現するための桁数、formatはprintfドキュメントに
詳述。 

  [例]

--> a=num2str(pi,'%f')

a =

3.14159


--> who a
Variable Name Type Flags Size
a string [1 9]


------------------------------------------------------------------------------------------------

diag 斜め配列を作成・抽出
[構文]
 y = diag(x,n)

xは配列、nは斜め行列の次元です。

[例]

(1) ベクトルから行列

--> x = int32(10*rand(1,3))

x =

6 4 9

--> diag(x)

ans =

6 0 0
0 4 0
0 0 9

--> diag(x,-1)

ans =

0 0 0 0
6 0 0 0
0 4 0 0
0 0 9 0
(2) 行列からベクトル
--> A = int32(10*rand(4,5))

A =

3 5 3 5 8
2 6 8 7 5
3 2 5 5 3
5 4 1 7 0

--> diag(A)

ans =

3
6
5
7

--> diag(A,1)

ans =

5
8
5
0

------------------------------------------------------------------------------------------------

repmat 配列の繰り返し
[構文]
 y = repmat(x,n)
 y = repmat(x,m,n)
 y = repmat(x,[m n p...])

  [例]

(1) 次元が2次元

--> x = [1 2 3 4]

x =

1 2 3 4

--> y=repmat(x,5,1)

y =

1 2 3 4
1 2 3 4
1 2 3 4
1 2 3 4
1 2 3 4

--> y = repmat(x,[5,1])

y =

1 2 3 4
1 2 3 4
1 2 3 4
1 2 3 4
1 2 3 4


(2) 次元が3次元の時

--> x = [1 2;3 4]

x =

1 2
3 4

--> y = repmat(x,[1,1,3])

y =

(:,:,1) =

1 2
3 4

(:,:,2) =

1 2
3 4

(:,:,3) =

1 2
3 4


-------------------------------------------------------------------------------------------------
permute 配列を配置しなおす

[構文]
 y = permute(x,p) 
xは配置しなおす配列、pは配置ベクトルです。 

[例]

(1)

--> A = [1,2;4,5]

A =

1 2
4 5

--> permute(A,[2,1])

ans =

1 4
2 5

--> A'

ans =

1 4
2 5
(2) 
--> A = randn(13,5,7,2);
--> size(A)

ans =

13 5 7 2

--> B = permute(A,[3,4,2,1]);
--> size(B)

ans =

7 2 5 13

------------------------------------------------------------------------------------------------

配列の自動リサイズ
FreeMatは、必要に応じて自動的にサイズを変更します。サイズを大きく
する際には定義が明確でない部分には0が挿入されます。 

  [例]

--> a = 1

a =

1


--> a(3) = 4

a =

1 0 4

-----------------------------------------------------------------------------------------------

値の割り当て
  [構文]
 a(ndx) = val
 a(ndx_1,ndx_2,..,ndx_m) = val
 a{ndx} = val
 a{ndx_1,ndx_2,...,ndx_m} = val 

  [例]

(1)

--> clear all
--> a(2)=3

a =

0 3
(2)

--> clear all
--> a(5:10)=5

a =

0 0 0 0 5 5 5 5 5 5

------------------------------------------------------------------------------------------------
circshift 配列を円形にシフトする

  [構文]
 y = circshift(x,shiftvec)
shiftvecにはどちらの次元にどれだけシフトさせるか、を表すベクトルが
設定される。

  [例]

(1) 配列が2次元の場合

--> x = int32(rand(4,5)*10)

x =

1 3 1 4 0
7 2 7 2 4
4 0 1 1 8
3 6 7 3 5

--> circshift(x,[1,0])

ans =

3 6 7 3 5
1 3 1 4 0
7 2 7 2 4
4 0 1 1 8

--> circshift(x,[0,-1])

ans =

3 1 4 0 1
2 7 2 4 7
0 1 1 8 4
6 7 3 5 3

--> circshift(x,[2,2])

ans =

1 8 4 0 1
3 5 3 6 7
4 0 1 3 1
2 4 7 2 7


(2) 配列が3次元の場合

--> x = int32(rand(4,5,3)*10)

x =

(:,:,1) =

6 5 1 7 3
7 3 5 5 0
3 7 6 6 7
3 8 5 8 0

(:,:,2) =

7 2 7 1 8
6 8 5 0 2
6 9 4 3 6
7 4 1 7 6

(:,:,3) =

1 0 1 9 6
7 5 5 7 5
4 2 6 6 5
5 2 4 5 1

--> circshift(x,[1,0,0])

ans =

(:,:,1) =

3 8 5 8 0
6 5 1 7 3
7 3 5 5 0
3 7 6 6 7

(:,:,2) =

7 4 1 7 6
7 2 7 1 8
6 8 5 0 2
6 9 4 3 6

(:,:,3) =

5 2 4 5 1
1 0 1 9 6
7 5 5 7 5
4 2 6 6 5

--> circshift(x,[0,-1,0])

ans =

(:,:,1) =

5 1 7 3 6
3 5 5 0 7
7 6 6 7 3
8 5 8 0 3

(:,:,2) =

2 7 1 8 7
8 5 0 2 6
9 4 3 6 6
4 1 7 6 7

(:,:,3) =

0 1 9 6 1
5 5 7 5 7
2 6 6 5 4
2 4 5 1 5

--> circshift(x,[0,0,-1])

ans =

(:,:,1) =

7 2 7 1 8
6 8 5 0 2
6 9 4 3 6
7 4 1 7 6

(:,:,2) =

1 0 1 9 6
7 5 5 7 5
4 2 6 6 5
5 2 4 5 1

(:,:,3) =

6 5 1 7 3
7 3 5 5 0
3 7 6 6 7
3 8 5 8 0

--> circshift(x,[2,-3,1])

ans =

(:,:,1) =

6 5 4 2 6
5 1 5 2 4
9 6 1 0 1
7 5 7 5 5

(:,:,2) =

6 7 3 7 6
8 0 3 8 5
7 3 6 5 1
5 0 7 3 5

(:,:,3) =

3 6 6 9 4
7 6 7 4 1
1 8 7 2 7
0 2 6 8 5


----------------------------------------------------------------------------------------------
flipdim 指定された次元で反転

  [構文]
 y = flipdim(x,n) 
nは反転させる次元 

  [例]

--> x = int32(rand(4,5,3)*10)

x =

(:,:,1) =

8 0 2 6 6
2 0 6 9 5
4 5 6 2 9
5 3 8 1 6

(:,:,2) =

7 7 4 2 4
5 8 5 3 1
2 2 7 9 9
6 0 7 0 2

(:,:,3) =

3 2 0 7 1
4 6 0 6 3
5 2 1 7 2
6 2 6 7 1

--> flipdim(x,1)

ans =

(:,:,1) =

5 3 8 1 6
4 5 6 2 9
2 0 6 9 5
8 0 2 6 6

(:,:,2) =

6 0 7 0 2
2 2 7 9 9
5 8 5 3 1
7 7 4 2 4

(:,:,3) =

6 2 6 7 1
5 2 1 7 2
4 6 0 6 3
3 2 0 7 1

--> flipdim(x,2)

ans =

(:,:,1) =

6 6 2 0 8
5 9 6 0 2
9 2 6 5 4
6 1 8 3 5

(:,:,2) =

4 2 4 7 7
1 3 5 8 5
9 9 7 2 2
2 0 7 0 6

(:,:,3) =

1 7 0 2 3
3 6 0 6 4
2 7 1 2 5
1 7 6 2 6

--> flipdim(x,3)

ans =

(:,:,1) =

3 2 0 7 1
4 6 0 6 3
5 2 1 7 2
6 2 6 7 1

(:,:,2) =

7 7 4 2 4
5 8 5 3 1
2 2 7 9 9
6 0 7 0 2

(:,:,3) =

8 0 2 6 6
2 0 6 9 5
4 5 6 2 9
5 3 8 1 6


-------------------------------------------------------------------------------------------------
fliplr 列の要素を固定して列を反転
 [構文]
 y = fliplr(x)

 [例]

(1)配列が2次元の場合

--> x = int32(rand(4)*10)

x =

8 0 5 0
5 0 0 6
7 5 9 4
6 3 7 0

--> fliplr(x)

ans =

0 5 0 8
6 0 0 5
4 9 5 7
0 7 3 6

(2) 配列が3次元の場合

--> x = int32(rand(4,4,3)*10)

x =

(:,:,1) =

1 6 6 7
8 3 3 3
8 0 9 3
0 9 3 0

(:,:,2) =

8 2 5 5
9 7 3 9
1 6 3 2
3 6 7 4

(:,:,3) =

6 6 6 8
3 4 6 4
9 7 8 5
8 5 5 4

--> fliplr(x)

ans =

(:,:,1) =

7 6 6 1
3 3 3 8
3 9 0 8
0 3 9 0

(:,:,2) =

5 5 2 8
9 3 7 9
2 3 6 1
4 7 6 3

(:,:,3) =

8 6 6 6
4 6 4 3
5 8 7 9
4 5 5 8


--------------------------------------------------------------------------------------------------------

flipud 行の要素を固定して行を反転
  [構文]
 y = flipud(x) 

  [例]

(1) 配列が2次元の場合
--> x = int32(rand(4)*10)

x =

7 3 1 1
1 4 4 3
8 7 8 2
5 3 1 8

--> flipud(x)

ans =

5 3 1 8
8 7 8 2
1 4 4 3
7 3 1 1

(2) 配列が3次元の場合

--> x = int32(rand(4,4,3)*10)

x =

(:,:,1) =

7 6 0 2
7 8 6 9
5 7 0 9
3 6 9 4

(:,:,2) =

8 6 9 5
9 6 3 3
3 4 5 4
7 3 6 9

(:,:,3) =

6 4 6 1
3 6 6 8
1 5 4 4
7 9 6 6

--> flipud(x)

ans =

(:,:,1) =

3 6 9 4
5 7 0 9
7 8 6 9
7 6 0 2

(:,:,2) =

7 3 6 9
3 4 5 4
9 6 3 3
8 6 9 5

(:,:,3) =

7 9 6 6
1 5 4 4
3 6 6 8
6 4 6 1


-------------------------------------------------------------------------------------------------

ipermute 配列の再配置
  [構文]
 y = ipermute(x,p) 
pは配置ベクトル(1...ndims(x))。 

  [例]


--> A = randn(13,5,7,2);
--> size(A)

ans =

13 5 7 2

--> B = permute(A,[3,4,2,1]);
--> size(B)

ans =

7 2 5 13

--> C = ipermute(B,[3,4,2,1]);
--> size(C)

ans =

13 5 7 2

--> any(A~=C)

ans =

0

-----------------------------------------------------------------------------------------------
isfloat 浮動小数点型の判定
  [構文]
 x = isfloat(y) 

  [例]

--> clear all
--> a=1

a =

1

--> isfloat(a)

ans =

0

-----------------------------------------------------------------------------------------------
isinteger 整数型の判定
  [構文]
 x = isinteger(y) 

  [例]

--> clear all
--> a=1

a =

1

--> isinteger(a)

ans =

1

-------------------------------------------------------------------------------------------------
linspace 等間隔ベクトルを作成
 [ 構文]
 y = linspace(a,b,count)
 y = linspace(a,b);
デフォルトはcount=100 。 

  [例]


--> x = linspace(0,1,5)

x =

0 0.2500 0.5000 0.7500 1.0000

-------------------------------------------------------------------------------------------------
logspace 等間隔対数ベクトルを作成
  [構文]
 y = logspace(a,b,count)
 y = logspace(a,b)

デフォルトはcount=100 。

 y = logspace(a,pi)

10^aからpiまでPaulo Xavier Candeias分布(GPL)に従います。

  [例]


--> logspace(1,2,3)

ans =

1.0e+02 *

0.1000 0.3162 1.0000

------------------------------------------------------------------------------------------------
meshgrid プロットのためのグリッドメッシュを作成
  [構文]
 [X,Y] = meshgrid(x)
[X,Y] = meshgrid(x,y)
[X,Y,Z] = meshgrid(x,y,z)
 x,y,zはベクトル、X,Y,Zは配列です。

  [例]

(1)
--> [X,Y] = meshgrid(-2:.4:2)
X =

Columns 1 to 10

-2.0000 -1.6000 -1.2000 -0.8000 -0.4000 -0.0000 0.4000 0.8000 1.2000 1.6000
-2.0000 -1.6000 -1.2000 -0.8000 -0.4000 -0.0000 0.4000 0.8000 1.2000 1.6000
-2.0000 -1.6000 -1.2000 -0.8000 -0.4000 -0.0000 0.4000 0.8000 1.2000 1.6000
-2.0000 -1.6000 -1.2000 -0.8000 -0.4000 -0.0000 0.4000 0.8000 1.2000 1.6000
-2.0000 -1.6000 -1.2000 -0.8000 -0.4000 -0.0000 0.4000 0.8000 1.2000 1.6000
-2.0000 -1.6000 -1.2000 -0.8000 -0.4000 -0.0000 0.4000 0.8000 1.2000 1.6000
-2.0000 -1.6000 -1.2000 -0.8000 -0.4000 -0.0000 0.4000 0.8000 1.2000 1.6000
-2.0000 -1.6000 -1.2000 -0.8000 -0.4000 -0.0000 0.4000 0.8000 1.2000 1.6000
-2.0000 -1.6000 -1.2000 -0.8000 -0.4000 -0.0000 0.4000 0.8000 1.2000 1.6000
-2.0000 -1.6000 -1.2000 -0.8000 -0.4000 -0.0000 0.4000 0.8000 1.2000 1.6000
-2.0000 -1.6000 -1.2000 -0.8000 -0.4000 -0.0000 0.4000 0.8000 1.2000 1.6000

Columns 11 to 11

2.0000
2.0000
2.0000
2.0000
2.0000
2.0000
2.0000
2.0000
2.0000
2.0000
2.0000

Y =

Columns 1 to 10

-2.0000 -2.0000 -2.0000 -2.0000 -2.0000 -2.0000 -2.0000 -2.0000 -2.0000 -2.0000
-1.6000 -1.6000 -1.6000 -1.6000 -1.6000 -1.6000 -1.6000 -1.6000 -1.6000 -1.6000
-1.2000 -1.2000 -1.2000 -1.2000 -1.2000 -1.2000 -1.2000 -1.2000 -1.2000 -1.2000
-0.8000 -0.8000 -0.8000 -0.8000 -0.8000 -0.8000 -0.8000 -0.8000 -0.8000 -0.8000
-0.4000 -0.4000 -0.4000 -0.4000 -0.4000 -0.4000 -0.4000 -0.4000 -0.4000 -0.4000
-0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000
0.4000 0.4000 0.4000 0.4000 0.4000 0.4000 0.4000 0.4000 0.4000 0.4000
0.8000 0.8000 0.8000 0.8000 0.8000 0.8000 0.8000 0.8000 0.8000 0.8000
1.2000 1.2000 1.2000 1.2000 1.2000 1.2000 1.2000 1.2000 1.2000 1.2000
1.6000 1.6000 1.6000 1.6000 1.6000 1.6000 1.6000 1.6000 1.6000 1.6000
2.0000 2.0000 2.0000 2.0000 2.0000 2.0000 2.0000 2.0000 2.0000 2.0000

Columns 11 to 11

-2.0000
-1.6000
-1.2000
-0.8000
-0.4000
-0.0000
0.4000
0.8000
1.2000
1.6000
2.0000
(2)
--> [X,Y] = meshgrid([1,2,3,4],[6,7,8])
X =

1 2 3 4
1 2 3 4
1 2 3 4

Y =

6 6 6 6
7 7 7 7
8 8 8 8


-----------------------------------------------------------------------------------------------

ndgrid N次元グリッドの作成
  [構文]
 [y1, y2, ..., ym] = ndgrid(x1, x2, ..., xn)
 [y1, y2, ..., ym] = ndgrid(x1)

2つ目の構文は、1つ目の構文のx1=x2=・・・・xnの場合。

  [例]

(1)

--> [a,b] = ndgrid(1:2,3:5)
a =

1 1 1
2 2 2

b =

3 4 5
3 4 5

--> [a,b,c] = ndgrid(1:2,3:5,0:1)
a =

(:,:,1) =

1 1 1
2 2 2

(:,:,2) =

1 1 1
2 2 2

b =

(:,:,1) =

3 4 5
3 4 5

(:,:,2) =

3 4 5
3 4 5

c =

(:,:,1) =

0 0 0
0 0 0

(:,:,2) =

1 1 1
1 1 1


(2)

--> [a,b,c] = ndgrid(1:3)
a =

(:,:,1) =

1 1 1
2 2 2
3 3 3

(:,:,2) =

1 1 1
2 2 2
3 3 3

(:,:,3) =

1 1 1
2 2 2
3 3 3

b =

(:,:,1) =

1 2 3
1 2 3
1 2 3

(:,:,2) =

1 2 3
1 2 3
1 2 3

(:,:,3) =

1 2 3
1 2 3
1 2 3

c =

(:,:,1) =

1 1 1
1 1 1
1 1 1

(:,:,2) =

2 2 2
2 2 2
2 2 2

(:,:,3) =

3 3 3
3 3 3
3 3 3


-----------------------------------------------------------------------------------------------

nonzeros 否ゼロの要素を抽出
  [構文]
 y = nonzeros(x)
  [例]
(1)

--> a=eye(3)

a =

1 0 0
0 1 0
0 0 1

--> nonzeros(a)

ans =

1
1
1

(2)

--> a = rand(8); a(a>0.2) = 0;
--> A = sparse(a)

A =
Matrix is sparse with 19 nonzeros
--> nonzeros(A)

ans =

0.1767
0.0337
0.1943
0.0846
0.0200
0.1884
0.0519
0.0745
0.0538
0.0838
0.0560
0.1657
0.0433
0.1788
0.1374
0.1702
0.0513
0.1767
0.0528
-------------------------------------------------------------------------------------------------
shiftdim 次元の変更
  [構文]
 y = shiftdim(x,n)
 [Y,N] = shiftdim(x) 
nが正なら左側に次元をシフトする。負なら右側。 

  [例]

(1)
--> x = uint8(10*randn(1,1,1,3,2));
--> size(x)

ans =

1 1 1 3 2
--> y=shiftdim(x,1);
--> size(y)

ans =

1 1 3 2
--> y=shiftdim(x,2);
--> size(y)

ans =

1 3 2
--> y=shiftdim(x,-1);
--> size(y)

ans =

1 1 1 1 3 2
(2) 
--> [y,n] = shiftdim(x);
--> n

ans =

3

--> size(y)

ans =

3 2

--> c = shiftdim(y,-n);
--> size(c)

ans =

1 1 1 3 2

--> any(c~=x)

ans =

0

--> z = shiftdim(x,4);
--> squeeze(x)

ans =

254 0
17 6
245 7

--> squeeze(z)

ans =

254 17 245
0 6 7


------------------------------------------------------------------------------------------------
squeeze 冗長な次元を削除
  [構文]
 y = squeeze(x)
  [例]

--> x = zeros(1,4,3,1,1,2);
--> size(x)

ans =

1 4 3 1 1 2

--> y = squeeze(x);
--> size(y)

ans =

4 3 2
---------------------------------------------------------------------------------------------
cond 
 [構文]
 y = cond(A) 
 y = cond(A,p)

 [例]


-----------------------------------------------------------------------------------------------

det 行列式
 [構文]

[例]






------------------------------------------------------------------------------------------------
expm 配列Exponential
[構文]

[例]






---------------------------------------------------------------------------------------------
eye 単位行列
[構文]

[例]






----------------------------------------------------------------------------------------------
norm ノルム
[構文]

[例]






----------------------------------------------------------------------------------------------
pinv 擬似逆行列(Moore-Penrose Pseudoinverse
[構文]

[例]






-----------------------------------------------------------------------------------------------
rank ランク
[構文]

[例]






----------------------------------------------------------------------------------------------
rref 列を減らす
[構文]

[例]






---------------------------------------------------------------------------------------------
transpose 転置
[構文]

[例]