MATLAB 05-2

신예진·2022년 1월 27일
0

Matlab Simulink

목록 보기
10/17

1) cell array

use {} (either left or right of = ) for cell array
collection of heterogeneous data

* make sure a is not in memory before doing the following
a{1,1} = 'John Smith' % same as a(1,1) = {'John Smith'}
a(1,2) = {67.25} % same as a{1,2} = 67.25
a{2,1} = rand(2,1) > 0.5 % same as a(2,1) = {rand(2,1) > 0.5}
a(2,2) = {rand(2)} % same as a{2,2} = rand(2)
a{2,2}(1,2) % a(2,2)에 저장했던 matrix의 (1,2)의 값을 알려줌.
cellplot(a)

2) structure array

use field(string) instead of subscript(number)

collection of heterogeneous data
guest.name = 'A Kim' % string array
guest.room = 306 % scalar number
guest.data = rand(3,2) % number array
whos guest

can easily extend to 1D or 2D array 
guest(2).discount = 0
guest(3).name = 'Andy Park'
whos guest

0개의 댓글