Attempt to extract field 'pmv' from 'mxArray'
5 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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.
0 comentarios
Respuestas (1)
Walter Roberson
el 7 de En. de 2024
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 comentarios
Walter Roberson
el 7 de En. de 2024
Ah, so then instead of
pmvx= struct('pmv', [], 'ppd', []);
you need to initialize it as a py.dict (somehow)
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!