Main Content

MATLAB에서 Python tuple 변수 사용하기

이 예제에서는 MATLAB®에서 Python® tuple 변수를 사용하는 방법을 보여줍니다.

tuple을 MATLAB 변수로 변환하기

tuple을 MATLAB 셀형 배열로 변환하려면 cell 함수를 호출하십시오.

pStudent = py.tuple({'Robert',19,'Biology'})
pStudent = 
  Python tuple with values:

    ('Robert', 19.0, 'Biology')

    Use string, double or cell function to convert to a MATLAB array.

S = cell(pStudent)
S=1×3 cell array
    {1×6 py.str}    {[19]}    {1×7 py.str}

tuple의 요소 읽기

MATLAB 인덱싱을 사용하여 tuple의 요소를 표시합니다. 예를 들어 pStudent의 처음 2개 요소를 표시해 보겠습니다. MATLAB은 tuple 변수를 반환합니다.

pStudent(1:2)
ans = 
  Python tuple with values:

    ('Robert', 19.0)

    Use string, double or cell function to convert to a MATLAB array.

요소 하나를 표시합니다. MATLAB은 Python 데이터형 요소를 반환합니다.

pStudent{3}
ans = 
  Python str with no properties.

    Biology

단일 요소를 포함하는 tuple 만들기

단일 요소를 가지는 tuple 변수를 만듭니다. MATLAB은 요소가 하나인 tuple에 대해 후행 쉼표를 표시합니다.

subject = py.tuple({'Biology'})
subject = 
  Python tuple with values:

    ('Biology',)

    Use string, double or cell function to convert to a MATLAB array.