필터 지우기
필터 지우기

Attempt to extract field 'pmv' from 'mxArray'

조회 수: 5 (최근 30일)
Shray
Shray 2024년 1월 6일
댓글: Walter Roberson 2024년 1월 7일
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