MATLAB での Python tuple
変数の使用
この例では、MATLAB® で Python® の tuple
変数を使用する方法を説明します。
tuple
から MATLAB 変数への変換
tuple
を MATLAB cell 配列に変換するには、関数 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.
1 つの要素を表示します。MATLAB は Python データ型要素を返します。
pStudent{3}
ans = Python str with no properties. Biology
単一の要素をもつ tuple
の作成
単一の要素をもつ tuple
変数を作成します。MATLAB は、要素が 1 つの tuple
に対しては末尾にコンマを表示します。
subject = py.tuple({'Biology'})
subject = Python tuple with values: ('Biology',) Use string, double or cell function to convert to a MATLAB array.