- Hierarchy of data object (개체의 계층 구조?)
 
- Logical array 
 
- Character array
 
- Double array
 
- Multi-dimensional array
 
- Cell array
 
- Structure array
 
- Function Handle array
 
1. Logical array ¶
0 아니면 1. True or False
예제 1. 마방진에서 5보다 큰 숫자를 찾아낸다.
예제 2. 마방진에서 5보다 큰 숫자에 100값을 넣는다.
예제 3. 다음 3식을 한 줄의 명령어 합친 뒤 plot
y = sin(x), 0
y = exp(-x), 1
y = 3, 2
 
>> A = magic(3)
A =
     8     1     6
     3     5     7
     4     9     2
>> I = A > 5
I =
     1     0     1
     0     0     1
     0     1     0
>> whos
  Name      Size            Bytes  Class      Attributes
  A         3x3                72  double               
  I         3x3                 9  logical              
여기서 I 값의 1은 True, 0은 False를 나타낸다.
%% find 함수 사용 A = magic(3) A(find(A>5)) = 100 %% A 내부의 값이 5보다 큰 경우에 100으로 변경 A = magic(3) A(A>5) = 100
A =
     8     1     6
     3     5     7
     4     9     2
A =
   100     1   100
     3     5   100
     4   100     2
y = sin(x), 0
y = exp(-x), 1
y = 3, 2
x = 0:0.1:3; %x값을 0에서 3까지 0.1씩 증가시킨다. y = sin(x).* (x>0 & x<=1) + exp(-x).*(x>1 & x<=2) + 3*(x>2) plot(x,y)

[PNG image (8.31 KB)]
2. Character array (String) ¶
- Numeric Array와 인덱싱이 동일
 
str1 = 'what''s your name?' str2 = 'My name is xxx' str4 = [srt1 ' ' str2] char(str1, str2)
3. Double array ¶
>> pi
ans =
    3.1416
>> format long
>> pi
ans =
   3.141592653589793
>> 2*12.3
ans =
  24.600000000000001
>> format
>> pi
ans =
    3.1416
>> single(pi)
ans =
    3.1416
>> format long
>> single(pi)
ans =
   3.1415927
>> format bank
>> 1
ans =
          1.00
분수로 수를 표현하는 format
>> format rat
>> pi
ans =
     355/113  
4. Multi-dimensional array (3D array) ¶
>> A = magic(4)
A =
      16              2              3             13       
       5             11             10              8       
       9              7              6             12       
       4             14             15              1       
>> A(:,:,2)=pascal(4)
A(:,:,1) =
      16              2              3             13       
       5             11             10              8       
       9              7              6             12       
       4             14             15              1       
A(:,:,2) =
       1              1              1              1       
       1              2              3              4       
       1              3              6             10       
       1              4             10             20       
>> A(:,1,2)
ans =
       1       
       1       
       1       
       1       
>> A(2,2,2)
ans =
       2       
>> format compact
>> A = cat(3, magic(3), pascal(3))
A(:,:,1) =
     8     1     6
     3     5     7
     4     9     2
A(:,:,2) =
     1     1     1
     1     2     3
     1     3     6
5. Cell array ¶
- 여러개의 데이터 타입을 동시에 포함
 
- 각 셀은 단독 공간(a room)으로 간주한다.
 
x{1,1} = 'matlab'
x{1,2} = magic(4);
x{2,1} = @sin;
x{2,2} = struct('age', 20, 'sex', 'male');
cellplot(x, 'legend')

[PNG image (3.85 KB)]
>> x{1}
ans =
matlab
>> x{1,1}
ans =
matlab
>> x{1,2}
ans =
    16     2     3    13
     5    11    10     8
     9     7     6    12
     4    14    15     1
>> x{2,1}
ans = 
    @sin
>> x{2,2}
ans = 
    age: 20
    sex: 'male'
>> x{1,2}(:,3)
ans =
     3
    10
     6
    15
>> whos Name Size Bytes Class Attributes x 2x2 660 cellx{:} == x{1}, x{2},...
>> x
x = 
    'matlab'    [4x4 double]
    @sin        [1x1 struct]
>> x(:)
ans = 
    'matlab'
    @sin        
    [4x4 double]
    [1x1 struct]
>> x{:}
ans =
matlab
ans = 
    @sin
ans =
    16     2     3    13
     5    11    10     8
     9     7     6    12
     4    14    15     1
ans = 
    age: 20
    sex: 'male'
 x(1,1)과 x{1,1}은 다르다.
 x(1,1)과 x{1,1}은 다르다.
>> x(1,2)
ans = 
    [4x4 double]
>> x{1,2}
ans =
    16     2     3    13
     5    11    10     8
     9     7     6    12
     4    14    15     1
데이터 밀어내기
>> x(end,:) = {123 @sin}
x = 
    'matlab'    [4x4 double]
    [   123]    @sin    
셀 삭제
>> x
x = 
    'matlab'    [4x4 double]
    [   123]    @sin        
>> x(end,:) = []
x = 
    'matlab'    [4x4 double]









