Simulink MxArray for logical array

조회 수: 6 (최근 30일)
Tan Biru
Tan Biru 2014년 9월 1일
답변: Kaustubha Govind 2014년 9월 2일
'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

답변 (1개)

Kaustubha Govind
Kaustubha Govind 2014년 9월 2일

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by