FreeMat v4.0 日本語ドキュメント
チェック関数

 

ドキュメント目次

  • typeof  入力引数の型の判定
  • clear  変数のクリア
  • who  現在定義されている変数の表示
  • fieldnames  構造体のフィールド名
  • size  変数のサイズ
  • isset  変数が定義されているか、また空でないかの判定
  • exist  存在しているかの判定
  • issparse  疎行列の判定
  • isnan  Not-a-Numbersの判定
  • isinf  無限大の判定
  • where  プログラムスタック情報の取得
  • which  関数の情報を取得
  • isempty  空行列の判定
  • isa  変数の型判定
  • iscell  セル配列の判定
  • iscellstr  セル配列の文字列であることの判定
  • ischar  文字データの判定
  • isfield  構造体の判定
  • ishandle  グラフィックハンドルの判定
  • isinttype  整数データの判定
  • islogical  論理値データの判定
  • isnumeric  数値データの判定
  • isreal  実数データの判定
  • isscalar  スカラーの判定
  • isstr  文字列の判定
  • isstruct  構造体の判定
  • isvector  ベクトルの判定
  • length  長さ
  • ndims  次元の数
  • numel  要素数
  • ismatrix 要素が配列かどうかのチェック
  • issame 2つの配列が同一かどうかのチェック
  • issparse 要素が疎行列かどうかのチェック
  • maxdim 最大の次元
  • nnz 非ゼロの数
  • whos メモリに存在する現在の変数

--------------------------------------------------------------------
typeof 入力引数の型の判定

 [構文]
 y = typeof(x)
 * 'cell' for cell-arrays
* 'struct' for structure-arrays
* 'logical' for logical arrays
* 'uint8' for unsigned 8-bit integers
* 'int8' for signed 8-bit integers
* 'uint16' for unsigned 16-bit integers
* 'int16' for signed 16-bit integers
* 'uint32' for unsigned 32-bit integers
* 'int32' for signed 32-bit integers
* 'float' for 32-bit floating point numbers
* 'double' for 64-bit floating point numbers
* 'complex' for complex floating point numbers with 32-bits per field
* 'dcomplex' for complex floating point numbers with 64-bits per field
* 'string' for string arrays

 [例]
--> typeof({1})

ans =

cell



--> typeof(struct('foo',3))

ans =

struct




--> typeof(3>5)

ans =

logical




--> typeof(uint8(3))

ans =

uint8

--> typeof(int8(8))

ans =

int8

--> typeof(uint16(3))

ans =

uint16

--> typeof(int16(8))

ans =

int16

--> typeof(uint32(3))

ans =

uint32



--> typeof(-3)

ans =

int32

--> typeof(8)

ans =

int32




--> typeof(1.0f)

ans =

float

--> typeof(1.0D)

ans =

double

--> typeof(1.0f+i)

ans =

complex

--> typeof(1.0D+2.0D*i)

ans =

dcomplex

--------------------------------------------------------------------
clear 変数のクリア
 
 [構文]
 clear a1 a2 ...
clear 'all'
clear 'libs'
clear 'persistent'
clear 'global'
clear 'classes'
 
 [例]
--> a = 53

a =

53


--> clear a
--> a
Error: Undefined function or variable a
 


--> global x
--> x=1

x =

1

--> who x
Variable Name Type Flags Size
x int32 global [1 1]
--> y=1

y =

1

--> who
Variable Name Type Flags Size
ans double [0 0]
x int32 global [1 1]
y int32 [1 1]
--> clear 'global'
--> who
Variable Name Type Flags Size
ans double [0 0]
y int32 [1 1]
 
--------------------------------------------------------------------
who 現在定義されている変数の表示
 
 [構文]
 who
 who a1 a2 ... 
a1,a2...は変数。
 
 [例]
--> c = [1,2,3];
--> f = 'hello';
--> p = randn(1,256);
--> who
Variable Name Type Flags Size
c int32 [1 3]
f string [1 5]
p double [1 256]



--> who c
Variable Name Type Flags Size
c int32 [1 3]
--> who('c')
Variable Name Type Flags Size
c int32 [1 3]
 

--------------------------------------------------------------------
fieldnames 構造体のフィールド名

 [構文]
 x = fieldnames(y)
構造体を入力引数とし、セル配列を返します。

 [例]
--> y.foo = 3; y.goo = 'hello';
--> who y
Variable Name Type Flags Size
y struct [1 1]

--> x = fieldnames(y)

x =

['foo']
['goo'] 
--> who x
Variable Name Type Flags Size
x cell [2 1]

 

--------------------------------------------------------------------
size 変数のサイズ
 
 [構文]
 [d1,d2,...,dn] = size(x)
 d = size(x,n)
nは次元。 
 
 [例]
--> a = randn(23,12,5);
--> size(a)

ans =

23 12 5


--> size(a,2)

ans =

12  

--------------------------------------------------------------------
isset 変数が定義されているか、また空でないかの判定

 [構文]
 y = isset('name')
 [例] 
--> who
Variable Name Type Flags Size
--> isset('a')

ans =

0

--> a = [];
--> isset('a')

ans =

0

--> a = 2;
--> isset('a')

ans =

1

--------------------------------------------------------------------
exist 存在しているかの判定

 [構文]
 y = exist(item,kind)  
 y = exist(item)
kindには以下の5つよりひとつ選びます。
 * 'builtin' checks for built-in functions
* 'dir' checks for directories
* 'file' checks for files
* 'var' checks for variables
* 'all' checks all possibilities (same as leaving out kind)
出力は下記の中の1つとなります。 
 * 0 - if item does not exist
* 1 - if item is a variable in the workspace
* 2 - if item is an M file on the search path, a full pathname to a file, or an ordinary file on your search path
* 5 - if item is a built-in FreeMat function
* 7 - if item is a directory

 [例]
 function y = testfunc(a, b, c)
if (~exist('c'))
% c was not defined, so establish a default
c = 13;
end
y = a + b + c;



--> a = randn(3,5,2)

a =

(:,:,1) =

0.8887 -0.2749 -0.1202 0.2347 0.2815
-0.9052 0.2688 1.9047 -0.0533 -1.6196
-1.6519 0.1689 0.5134 -0.5795 0.7863

(:,:,2) =

0.8246 -0.5823 -0.6986 0.3591 -2.5987
-0.5022 2.4368 1.2679 -1.4748 -0.4239
-0.9966 -0.5530 -0.3325 2.2984 0.5024

--> b = []

b =
[]
--> who
Variable Name Type Flags Size
a double [3 5 2]
b double [0 0]
--> exist('a')

ans =

1

--> exist('b')

ans =

1

--> exist('c')

ans =

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

issparse 疎行列の判定

 [構文]
 y = issparse(x)

 [例]
--> a = [1,0,0,5;0,3,2,0]

a =

1 0 0 5
0 3 2 0

--> issparse(a)

ans =

0

--> A = sparse(a)

A =
Matrix is sparse with 4 nonzeros
--> issparse(A)

ans =

1
--------------------------------------------------------------------
isnan Not-a-Numberの判定
 
 [構文]
 y = isnan(x) 
 
 [例]
--> a = [1.2 3.4 nan 5]

a =

1.2000 3.4000 nan 5.0000

--> isnan(a)

ans =

0 0 1 0  
--------------------------------------------------------------------
isinf 無限大の判定
 
 [構文]
 y = isinf(x) 
 
 [例]
--> a = [1.2 3.4 inf 5]

a =

1.2000 3.4000 inf 5.0000

--> isinf(a)

ans =

0 0 1 0

--> b = 3./[2 5 0 3 1]

b =

1.5000 0.6000 inf 1.0000 3.0000  

--------------------------------------------------------------------
where プログラムスタック情報の取得
 
 [構文]
 where 
 
  [例]
     chain1.m
function chain1
  a = 32;
  b = a + 5;
  chain2(b)


     chain2.m
function chain2(d)
  d = d + 5;
  chain3


     chain3.m
function chain3
  g = 54;
  f = g + 1;
  keyboard


--> chain1
[chain3,4]--> where
In base(base) on line 0
In simkeys(built in) on line 0
In Eval(chain1) on line 2
In chain1(chain1) on line 4
In chain2(chain2) on line 4
In chain3(chain3) on line 4
In Eval(where) on line 2
In where(built in) on line 0
[chain3,4]

--------------------------------------------------------------------
which 関数の情報を取得
 
 [構文]
 which(fname)
 y = which(fname) 
 
 [例]
--> which fft
Function fft is a built in function


--> which fliplr
Function fliplr, M-File function in file '/home/basu/dev/trunk/FreeMat2/src/toolbox/array/fliplr.m'

--------------------------------------------------------------------
isempty 空行列の判定
 
 [構文]
 y = isempty(x) 
 
 [例]
--> a = []

a =
[]
--> isempty(a)

ans =

1

--> b = 1:3

b =

1 2 3

--> isempty(b)

ans =

0



--> clear x
--> isempty(x)
Error: Undefined function or variable x

--------------------------------------------------------------------
isa 変数の型判定
 
 [構文]
 y = isa(x,type) 
  
 [例]
--> a = {1}

a =

[1]

--> isa(a,'string')

ans =

0

--> isa(a,'cell')

ans =

1


--> a = 'hello'

a =

hello

--> isa(a,'string') && strcmp(a,'hello')

ans =

1
 

--------------------------------------------------------------------
iscell セル配列の判定

 [構文]
 x = iscell(y) 
 
 [例]
--> iscell('foo')

ans =

0

--> iscell(2)

ans =

0

--> iscell({1,2,3})

ans =

1  
 

--------------------------------------------------------------------
iscellstr セル配列の文字列かどうかの判定

 [構文]
 x = iscellstr(y) 
 
 [例]
--> A = {'Hello','Yellow';'Mellow','Othello'}

A =

['Hello'] ['Yellow']
['Mellow'] ['Othello']

--> iscellstr(A)

ans =

1  
--------------------------------------------------------------------
ischar 文字データの判定
 
 [構文]
 x = ischar(y) 
 
 [例]
--> y='test';
--> ischar(y)

ans =

--------------------------------------------------------------------
isfield 構造体の判定
 
 [構文]
 y = isfield(x,field)
 
 [例]
--> a.foo = 32

a =
foo: [32]
--> a.goo = 64

a =
foo: [32]
goo: [64]
--> isfield(a,'goo')

ans =

1

--> isfield(a,'got')

ans =

0

--> isfield(pi,'round')

ans =

0  

--------------------------------------------------------------------
ishandle グラフィックハンドルの判定

 [構文]
 y = ishandle(h,type) 
 
 [例]

--------------------------------------------------------------------
isinttype 整数データの判定

 [構文]
 x = isinttype(y) 
 
 [例]
--> isinttype(1)

ans =

1

--> isinttype(1.1)

ans =

0

 
--------------------------------------------------------------------
islogical 論理値データの判定
 
 [構文]
 x = islogical(y) 
 
 [例]
--> islogical(1)

ans =

0

--> islogical(1==1)

ans =

1
 
--------------------------------------------------------------------
isnumeric 数値データの判定
 
 [構文]
 x = isnumeric(y) 
 
 [例]
--> isnumeric(char(1))

ans =

0

--> isnumeric({1,1})

ans =

0

--> isnumeric(1)

ans =

1
 
--------------------------------------------------------------------
isreal 実数データの判定
 
 [構文]
 x = isreal(y)
 
 [例]
--> isreal(1+i)

ans =

0
 
--------------------------------------------------------------------
isscalar スカラーの判定
 
 [構文]
 x = isscalar(y) 
 
 [例]
--> isscalar([1 1])

ans =

0

--> isscalar(1)

ans =

 
--------------------------------------------------------------------
isstr 文字列の判定
 
 [構文]
 x = isstr(y) 
 
 [例]
--> isstr('111')

ans =

1

--> isstr(111)

ans =

 
--------------------------------------------------------------------
isstruct 構造体の判定
 
 [構文]
 x = isstruct(y) 
 
 [例]
--> y=struct('aaa',10);
--> isstruct(y)

ans =

1

--------------------------------------------------------------------
isvector ベクトルの判定
 
 [構文]
 x = isvector(y) 
 
 [例]
--> a=rand(3)

a =

0.3759 0.3580 0.0990
0.0183 0.7604 0.4972
0.9134 0.8077 0.3478

--> isvector(a)

ans =

0
 
--------------------------------------------------------------------
length 長さの算出
 
 [構文]
 y = length(x)
 
 [例]
--> x = rand(4,4,3);
--> length(x)

ans =

4  
 
--------------------------------------------------------------------
ndims 次元の数
 
 [構文]
 n = ndims(x) 
length(size(x))と同じ。
  
 [例] 
--> a=rand(3)

a =

0.0276 0.2079 0.3365
0.5313 0.4921 0.8670
0.9958 0.7597 0.2714

--> ndims(a)

ans =

2

--------------------------------------------------------------------
numel 要素数
 
 [構文]
 y = numel(x)
 y = numel(x,varargin)
 
 [例]
--> x = rand(4,4,3);
--> length(x)

ans =

4

--> numel(x)

ans =

48



--> numel(x,1:3,1:2,2)

ans =

6
 
 
----------------------------------------------------------
ismatrix 要素が配列かどうかのチェック
 
 [構文]
   x = ismatrix(y)
 
 [例]
 
----------------------------------------------------------
issame 2つの配列が同一かどうかのチェック
 
 [構文]
   y = issame(a,b)
 
 [例]
--> issame(1,1)
ans =
 1
--> issame(1,0)
ans =
 0
 
----------------------------------------------------------
issparse 要素が疎行列かどうかのチェック
 
 [構文]
   y = issparse(x)
 
 [例]
--> a = [1,0,0,5;0,3,2,0]

a = 
 1 0 0 5 
 0 3 2 0 

--> issparse(a)

ans = 
 0 

--> A = sparse(a)

A = 
 1 1 1
 2 2 3
 2 3 2
 1 4 5
--> issparse(A)

ans = 
 1 
 
----------------------------------------------------------
maxdim 最大の次元
 
 [構文]
  n = maxdim(x)
 
 [例]
--> a=ones(3,100);
--> maxdim(a)
ans =
 2
--> a=ones(3,1,4,5);
--> maxdim(a)
ans =
 4
 
----------------------------------------------------------
nnz 非ゼロの数
 
 [構文]
   y = nnz(x)
 
 [例]
 
--> a = [1,0,0,5;0,3,2,0]

a = 
 1 0 0 5 
 0 3 2 0 

--> nnz(a)

ans = 
 4 

--> A = sparse(a)

A = 
 1 1 1
 2 2 3
 2 3 2
 1 4 5
--> nnz(A)

ans = 
 4 
----------------------------------------------------------
whos メモリに存在する現在の変数
 
 [構文]
  whos a1 a2 ...
  whos
 
 [例]
--> whos
  Variable Name       Type   Flags     Size       Bytes
              a    double            [3 1 4 5]       480
            ans    double            [0 0]           0