Trouble with matlab::data::Array
20 次查看(过去 30 天)
显示 更早的评论
The Array/StructArray is still very shady to me (why is there not (I cannot find...) a basic explanation from matlab instead of a handfull examples that just do not tell you what the whole idea behind Arrays, TypedArrays and StructArrays is?)....
I have the following:
matlab::data::Array myData;
void doSomethingWithElement(const matlab::data::Array& matlabArray) { ... }
for (size_t i = 0; i < myData.getNumberOfElements(); i++)
doSomethingWithElement(myData[i]);
This seems to crash at 'myData[i]' (tested separately) with the message 'Field does not exist in this struct.'. A separate test also crashes:
matlab::data::Array dummy = myData[0];
What am I doing wrong? Do I have to toss in 'matlab::data::ArrayFactory::createArray' in between?
0 个评论
回答(1 个)
Steven Lord
2023-7-7
Have you seen the first of the Topics on this documentation page, which I believe is a "basic explanation" of the C++ MATLAB Data API?
If the data you're working with is a MATLAB struct array you may want to use a matlab::data::StructArray (created from a matlab::data:ArrayFactory using its createStructArray method) instead of a plain matlab::data::Array.
I think you may be able to adapt the "Access Struct Array Data" example on this documentation page to retrieve the appropriate fields of the appropriate elements in your struct and pass them into you doSomethingWithElement function.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Structures 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!