Matlab coder logical indexing structs
2 次查看(过去 30 天)
显示 更早的评论
Hello,
I currently have a struct defined as such,
struct(1).a
struct(2).a
struct(3).a
...
struct(N).a
where the field a is a 3x3 matrix. When I'm attempting to convert Matlab code to C through the code I run into the follwing error when trying to access the above struct through a logical index, lg.
What I'm attempting:
b = blkdiag(struct(lg).a);
Error I get:
"Directly accessing field or property of nonscalar struct or object not supported for code code generation."
I'm not fully understanding the error. Furthermore isn't 'struct' a scalar struct in this case. Note: 'struct' does have other fields that are matrices, scalars and logicals as well.
2 个评论
Stephen23
2020-2-18
编辑:Stephen23
2020-2-18
"I currently have a struct defined as such,"
struct(1).a
struct(2).a
struct(3).a
...
struct(N).a
Hopefully you do NOT have a structure named struct. That would be a very unfortunate name for a structure, as it would shadow the inbuilt struct function.
"Furthermore isn't 'struct' a scalar struct in this case."
Only if N==1. If N~=1 then the structure is non-scalar.
Just like any other array, a scalar structure has size 1x1x1x1x1x1...
If N~=1, then regardless of what dimension it corresponds to, the structure cannot be scalar.
Note: the number of fields a structure has is completely independent of its size.
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Structures 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!