Simulink MxArray for logical array

4 views (last 30 days)
Tan Biru
Tan Biru on 1 Sep 2014
Answered: Kaustubha Govind on 2 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

Answers (1)

Kaustubha Govind
Kaustubha Govind on 2 Sep 2014

Categories

Find more on Simulink Functions in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!