How to resize/append to a matlab::data:StructArray using the MATLAB C++ API
조회 수: 3 (최근 30일)
이전 댓글 표시
I am implementing a function as a mex file in C++. In order to export internal data to MATLAB, I'm using the createStructArray function to preallocate a StructArray with n elements as below:
auto x = factory.createStructArray({ 1, n}, {"field1", "field2", "field3"});
I can then populate the fields of x something like this:
for (auto ii = 0; ii < n; ++ii) {
x[ii]["field1"] = factory.createScalar<double>(...);
x[ii]["field2"] = factory.createScalar<double>(...);
...
}
All good so far, however on a subsequent iteration of the function, I want to be able to append new data to an existing StructArray, which would require resizing the existing StructArray to, say, {1, n+n1}. Indexing outside of the preallocated range within MATLAB would automatically force a resize, however that doesn't work here. There doesn't appear to be any resize() or related functions in the API.
Is there a good way of resizing/appending new data to an existing StructArray that doesn't involve simply copying all of the existing elements to a new StructArray?
댓글 수: 0
답변 (1개)
Ted
2023년 11월 17일
I believe there is no such convenience. As you said at the end of your question, you will have to make a new larger array and copy the existing elements over.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 MATLAB Data API for C++에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!