C++ 셀형 배열
셀형 배열을 만들려면 matlab::data::ArrayFactory createCellArray 함수를 사용하십시오.
이 MATLAB® 명령문을 사용하여 정의된 MATLAB 셀형 배열과 동일한 CellArray를 만듭니다. 참고로, MATLAB은 셀을 열 우선 순서로 할당합니다.
C = {'Character Array',...
[true true false true];...
[2.2 3.3 -4.2 6.0],...
int32(-3374)};다음과 같이 ArrayFactory를 만듭니다.
matlab::data::ArrayFactory factory;
다음과 같이 createCellArray를 호출하고 셀형 배열에 포함된 각 셀을 정의합니다.
matlab::data::CellArray C = factory.createCellArray({ 2,2 },
factory.createCharArray("Character Array"),
factory.createArray<double>({ 1, 4 }, { 2.2, 3.3, -4.2, 6.0}),
factory.createArray<bool>({ 1, 4 }, { true, true, false, true }),
factory.createScalar<int32_t>(-3374)
);MATLAB에서 참조되는 셀의 값을 C{1,1}로 덮어써서 배열을 수정합니다.
C[0][0] = factory.createCharArray("New Character Array");
double형 배열이 포함된 셀에 대한 참조를 가져오고 첫 번째 요소를 -2.2로 변경합니다.
TypedArrayRef<double> doubleArray = C[1][0]; doubleArray[0] = -2.2;
double형 배열이 포함된 셀의 새 값을 표시합니다.
TypedArray<double> const newArray = C[1][0];
for (auto e : newArray) {
std::cout << e << std::endl;
}