Attempt to extract field 'ThermocoupleType' from 'mxArray'.

2 views (last 30 days)
I'm trying to write code in simulink block editor to take live input data from a thermocouple, through a DAQ system, to display the data on a scope. The thermocouple is a K type thermocouple. If I don't specify the type, I get an error message asking for the thermocouple type. When I specify K type, I get the error 'Attempt to extract field 'ThermocoupleType' from 'mxArray'.'
What should I do?
Code:
function data = Thermocouple()
coder.extrinsic('daq.createSession','addAnalogInputChannel','startForeground','T')
T = daq.createSession('ni');
ch0 = addAnalogInputChannel(T,'cDAQ9185-1D2BD3AMod2',0,'Thermocouple');
ch0.ThermocoupleType = 'k';
data = zeros(1,1000);
data = startForeground(T);
Thanks in advance!
  2 Comments
Venkata Siva Krishna Madala
Since "addAnalogInputChannel" is extrinsic, it returns an "mxArray" object, which overrides the data type of "ch0" to be an "mxArray" as well.
In order to solve this error pre-initialize the desired fields / variables, and then assign the value to the field.
Bob Dekraker
Bob Dekraker on 19 Jun 2018
Edited: Bob Dekraker on 19 Jun 2018
I'm not exactly sure what to preinitialize it to. Is this what you were thinking?
function data = Thermocouple()
coder.extrinsic('daq.createSession','addAnalogInputChannel','startForeground','T')
T = daq.createSession('ni');
ch0 = addAnalogInputChannel(T,'cDAQ9185-1D2BD3AMod2',0,'Thermocouple');
ch0.ThermocoupleType = zeros(1,1)
ch0.ThermocoupleType = 'k';
data = zeros(1,1000);
data = startForeground(T);
Thanks

Sign in to comment.

Answers (1)

cristina9
cristina9 on 12 Oct 2018
Edited: cristina9 on 12 Oct 2018
Same quesiton! I call "timedelaynet" to train a neural network on line in the simulink, and then hope to get the weight value of the neural network. I specify the type of the variable in advance, but it does not work.
coder.extrinsic('net'); net.IW{1,1}=zeros(5,4); %error message:Attempt to extract field 'IW' from 'mxArray' [net,tr]=train(net,inputs,targets,inputStates,layerStates);
What should I do?

Categories

Find more on Simulink Functions in Help Center and File Exchange

Products


Release

R2018a

Community Treasure Hunt

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

Start Hunting!