Simulink MxArray for logical array

3 Ansichten (letzte 30 Tage)
Tan Biru
Tan Biru am 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

Antworten (1)

Kaustubha Govind
Kaustubha Govind am 2 Sep. 2014

Kategorien

Mehr zu Simulink Functions finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by