Simulink MxArray for logical array

2 vues (au cours des 30 derniers jours)
Tan Biru
Tan Biru le 1 Sep 2014
'function [ index] = SoftMax( Q )
coder.extrinsic('softmax');
Temperature = 0.5; terms = Q/Temperature;
Prob = softmax (terms);
cummu = cumsum (Prob);
randm = rand();
index= sum(cummu <= randm) +1;'
Dear MATLAB community,
I am using this code on MATLAB Function block in Simulink. 'Q' is an array which made 'cummu' an array too. Running this function at MATLAB command windows doesn't have problems, but running in Simulink returns "Expected either a logical, char, int, fi, single, or double. Found an mxArray. MxArrays are returned from calls to the MATLAB interpreter and are not supported inside expressions. They may only be used on the right-hand side of assignments and as arguments to extrinsic functions." for 'index= sum(cummu <= randm) +1;'
I have also tried
'for i = 1:numel(Q) if(randm >= cump(i)) action = action +1; end end'
but it returns "Subscripting into an mxArray is not supported. ... ... cummu (i)... ..."
I am stuck on this, please help. Thank you!
Tan Biru

Réponses (1)

Kaustubha Govind
Kaustubha Govind le 2 Sep 2014

Catégories

En savoir plus sur Simulink Functions dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by