Linear indexing for multi-dimensional struct array in C++ API
Show older comments
In plain MATLAB I can use the following code and ignore the actual dimensions:
s = repmat(struct('exampleField',1),[2,3,4,5]);
for ii = 1:numel(s)
disp(s(ii).exampleField)
end
However, in the C++ API, I can't use the linear indexing as the following code fails with the error: "Not enough indices provided."
void func(matlab::data::StructArray s){
for (size_t ii = 0; ii < s.getNumberOfElements(); ++ii)
std::cout << s[ii][std::string("exampleField")] << std::endl;
}
Is there a way to still use linear indexing? Without linear indexing generic code development gets nearly impossible.
Accepted Answer
More Answers (0)
Categories
Find more on Call C++ from MATLAB in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!