Azzera filtri
Azzera filtri

Simulink: Error getting properties from an Extrinsic function

10 visualizzazioni (ultimi 30 giorni)
I am running a function in simulink simulation mode in a matlab block that contains factorGraph as an extrinsic function(code below).
[NumNodes, NumFactors] = SLAM();
function [NumNodes, NumFactors] = SLAM()
coder.extrinsic('factorGraph','addFactor','factorTwoPoseSE2');
G = factorGraph;
fctr = factorTwoPoseSE2([1 2], Measurement=[0 0 0]);
addFactor(G,fctr);
NumNodes = double(0.0); %#ok<NASGU>
NumFactors = double(0.0); %#ok<NASGU>
NumNodes = G.NumNodes;
NumFactors = G.NumFactors;
end
However I can't extract the properties of the factorGraph and get the following error (It works without issue in matlab):
Attempt to extract field 'NumNodes' from 'mxArray'.
Attempt to extract field 'NumFactors' from 'mxArray'.
I found:
and
To be relevent but their advice did not result in success.

Risposta accettata

Sanjana
Sanjana il 1 Mar 2023
Hi,
It appears that the issue is related to the class of the output from an extrinsic function ,specifically it is of type ‘mxArray’ i.e MATLAB Array .The only valid operations for an mxArray’ are storing it in a variable, passing it to another extrinsic function, or returning it to MATLAB. To perform any other operation on an mxArray’ value, such as using it in an expression in your code, you must convert the mxArray’ to a known type at run time. To perform this action, assign the mxArray’ to a variable whose type is already defined by a prior assignment. I have seen that, in your code you have preinitialized NumNodes and NumFactors, to the required output type, but here ‘G’ is also of class ‘mxArray’, so you cannot access ’ factorGraph’ Properties using ‘.’ Operation.
But then again, you cannot use ‘ factorGraph’ directly inside the 'MATLAB Function Block' as it doesn’t support code Generation for “factorGraph”. That will be a deadlock, so I would suggest you to find an alternative way to create custom Block Functionality in Simulink.
Please refer to this Documentation, for finding the best way to incorporate MATLAB code into a block in Simulink Model
For Understanding the working of MATALB Function Block, refer
For further Assistance you can refer,
Hope this helps!

Più risposte (0)

Prodotti


Release

R2022b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by