Trouble with matlab::data::Array
20 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponses (1)
Steven Lord
le 7 Juil 2023
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.
1 commentaire
Voir également
Catégories
En savoir plus sur Structures dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!