Attempt to extract field 'pmv' from 'mxArray'

5 次查看(过去 30 天)
Hello,
I am trying to create a MATLAB fuction for calculating PMV using already created Python Library. This function is being called into a simulink model. The code is as follows for custom simulink block:-
function [pmvf,ppdf] = PMV_BLOCK(tdb, tr, vr, rh, met, clo)
pmvf=0;
ppdf=0;
tr = 25;
tdb= 25;
rh = 50;
v = 0.1;
met = 1.3;
clo = 0.8;
coder.extrinsic('py.pythermalcomfort.utilities.v_relative');
v_r=py.pythermalcomfort.utilities.v_relative(v, met); %to calculate relative velocity from absolute velocity
coder.extrinsic('py.pythermalcomfort.utilities.clo_dynamic');
clo_d=py.pythermalcomfort.utilities.clo_dynamic(clo, met); %to calculate clothing insulation
coder.extrinsic('py.pythermalcomfort.pmv_ppd');
pmvx=py.pythermalcomfort.pmv_ppd(tdb, tr, v_r, rh, met, clo_d); %to calculate pmv and ppd
l=struct(pmvx);
pmvx.pmv
Whenevever i tries to run the matlab function block (via simulink model run), i get the following error message:-
Error :-
"Attempt to extract field 'pmv' from 'mxArray'. Function 'PMV Calculator' (#172.613.617), line 17, column 1: "pmvx" Launch diagnostic report."
Even after checking multiple websites no solution could be traced. My project requires me to calculate pmv through matlab function only (when called from Simulink run).
Any quick suggestion on how to extract values from mxarray in the matlab function block?
Thanks in advance.

回答(1 个)

Walter Roberson
Walter Roberson 2024-1-7
pmvx=py.pythermalcomfort.pmv_ppd(tdb, tr, v_r, rh, met, clo_d); %to calculate pmv and ppd
As far as Simulink knows, the result of that call is going to be numeric of some size or other. And then you try to extract a field from what is assumed to be numeric.
You need to first assign pmvx as a struct array with the same fields (in the same order) as py.pythermalcomfort.pmv_ppd will return. Then you assign pmvx as the result of that calls.
pmvx = struct('pmvorder', [], 'pmvx', [], 'pmvsmooth', [], 'pmvy', []);
pmvx = py.pythermalcomfort.pmv_ppd(tdb, tr, v_r, rh, met, clo_d); %to calculate pmv and ppd
except that the field names and orders have to match the real return value.
  3 个评论
Shray
Shray 2024-1-7
Even after declaring struct as an extrinsic function i am not able to extract values from pmvx? My original question still persists how to extract values from maxarray?
Thanks in advance
Walter Roberson
Walter Roberson 2024-1-7
Ah, so then instead of
pmvx= struct('pmv', [], 'ppd', []);
you need to initialize it as a py.dict (somehow)

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Programming 的更多信息

产品


版本

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by