Error of ‘Value’ must be a double scalar within the range of ‘Limits’ and Error using -. Arrays have incompatible sizes for this operation.
This is my first time coding in MATLAB and below is my code. The input is from an NI DAQ device, in the form of analog signals. The purpose of the code is to read live data from the hardware (which is attached to sensors), plot the live data real-time (surface plot) and calculate the mean and median of the live data. Currently, the error is
‘Value’ must be a double scalar within the range of ‘Limits’ for the line app.ThicknessMeanEditField.Value = app.plateMeanThickness; and app.ThicknessMedianEditField.Value = plateMedian;,
I have checked the data types of app.plateMeanThickness and plateMedian using class(), and both returns ‘double’. I used Edit Field (Numerical) for app.ThicknessMeanEditField and app.ThicknessMedianEditField, and the limits of both are from -inf to inf. This information is obtained from the Component Browser window, under Limits. I have tried using double() for the variables as well, but the same error still occurs. Therefore, I do not know how to resolve this as both aspects (the data being double scalar and within the range of limits) seem to be satisfied.
as well as Error using -. Arrays have incompatible sizes for this operation. for the line data = abs(z-init);
This line is used to calculate the difference between the initial values of the sensors (init) with the live data (z), which results to the dimension of an object. The source of init and z are exactly the same, with z being a matrix with infinite number of rows and 10 columns, and init being a row vector with the size of 1×10. According to forums, this should be compatible. But I might be wrong. I would really appreciate it if someone can help me solve these errors. I hope I have provided enough information. Thank you for your help in advance.
function readAndPlotSensors(app)
dq = daq("ni");
i1 = addinput(dq,"Dev1","ai8","Voltage");
i1.TerminalConfig = "SingleEnded";
i2 = addinput(dq,"Dev1","ai1","Voltage");
i2.TerminalConfig = "SingleEnded";
i3 = addinput(dq,"Dev1","ai9","Voltage");
i3.TerminalConfig = "SingleEnded";
i4 = addinput(dq,"Dev1","ai2","Voltage");
i4.TerminalConfig = "SingleEnded";
i5 = addinput(dq,"Dev1","ai10","Voltage");
i5.TerminalConfig = "SingleEnded";
i6 = addinput(dq,"Dev1","ai3","Voltage");
i6.TerminalConfig = "SingleEnded";
i7 = addinput(dq,"Dev1","ai11","Voltage");
i7.TerminalConfig = "SingleEnded";
i8 = addinput(dq,"Dev1","ai4","Voltage");
i8.TerminalConfig = "SingleEnded";
i9 = addinput(dq,"Dev1","ai12","Voltage");
i9.TerminalConfig = "SingleEnded";
i10 = addinput(dq,"Dev1","ai5","Voltage");
i10.TerminalConfig = "SingleEnded";
start(dq,"continuous");
init = read(dq, 1, "OutputFormat", "Matrix");
i=0;
i=i+1;
zlim(app.UIAxes, [0 40]);
colormap(app.UIAxes, turbo);
colorbar(app.UIAxes);
while(1)
z = read(dq, "all", "OutputFormat", "Matrix");
data = abs(z-init);
app.dataConv = data*15; %converts data from voltage to mm according to sensor
surf(app.UIAxes, app.dataConv’,"EdgeColor","none");
app.plateMeanThickness = mean(app.dataConv,"all");
app.ThicknessMeanEditField.Value = app.plateMeanThickness;
plateMedian = median(app.dataConv,"all");
app.ThicknessMedianEditField.Value = plateMedian;
app.plateThickness();
pause(0.5);
i=i+1;
end
endThis is my first time coding in MATLAB and below is my code. The input is from an NI DAQ device, in the form of analog signals. The purpose of the code is to read live data from the hardware (which is attached to sensors), plot the live data real-time (surface plot) and calculate the mean and median of the live data. Currently, the error is
‘Value’ must be a double scalar within the range of ‘Limits’ for the line app.ThicknessMeanEditField.Value = app.plateMeanThickness; and app.ThicknessMedianEditField.Value = plateMedian;,
I have checked the data types of app.plateMeanThickness and plateMedian using class(), and both returns ‘double’. I used Edit Field (Numerical) for app.ThicknessMeanEditField and app.ThicknessMedianEditField, and the limits of both are from -inf to inf. This information is obtained from the Component Browser window, under Limits. I have tried using double() for the variables as well, but the same error still occurs. Therefore, I do not know how to resolve this as both aspects (the data being double scalar and within the range of limits) seem to be satisfied.
as well as Error using -. Arrays have incompatible sizes for this operation. for the line data = abs(z-init);
This line is used to calculate the difference between the initial values of the sensors (init) with the live data (z), which results to the dimension of an object. The source of init and z are exactly the same, with z being a matrix with infinite number of rows and 10 columns, and init being a row vector with the size of 1×10. According to forums, this should be compatible. But I might be wrong. I would really appreciate it if someone can help me solve these errors. I hope I have provided enough information. Thank you for your help in advance.
function readAndPlotSensors(app)
dq = daq("ni");
i1 = addinput(dq,"Dev1","ai8","Voltage");
i1.TerminalConfig = "SingleEnded";
i2 = addinput(dq,"Dev1","ai1","Voltage");
i2.TerminalConfig = "SingleEnded";
i3 = addinput(dq,"Dev1","ai9","Voltage");
i3.TerminalConfig = "SingleEnded";
i4 = addinput(dq,"Dev1","ai2","Voltage");
i4.TerminalConfig = "SingleEnded";
i5 = addinput(dq,"Dev1","ai10","Voltage");
i5.TerminalConfig = "SingleEnded";
i6 = addinput(dq,"Dev1","ai3","Voltage");
i6.TerminalConfig = "SingleEnded";
i7 = addinput(dq,"Dev1","ai11","Voltage");
i7.TerminalConfig = "SingleEnded";
i8 = addinput(dq,"Dev1","ai4","Voltage");
i8.TerminalConfig = "SingleEnded";
i9 = addinput(dq,"Dev1","ai12","Voltage");
i9.TerminalConfig = "SingleEnded";
i10 = addinput(dq,"Dev1","ai5","Voltage");
i10.TerminalConfig = "SingleEnded";
start(dq,"continuous");
init = read(dq, 1, "OutputFormat", "Matrix");
i=0;
i=i+1;
zlim(app.UIAxes, [0 40]);
colormap(app.UIAxes, turbo);
colorbar(app.UIAxes);
while(1)
z = read(dq, "all", "OutputFormat", "Matrix");
data = abs(z-init);
app.dataConv = data*15; %converts data from voltage to mm according to sensor
surf(app.UIAxes, app.dataConv’,"EdgeColor","none");
app.plateMeanThickness = mean(app.dataConv,"all");
app.ThicknessMeanEditField.Value = app.plateMeanThickness;
plateMedian = median(app.dataConv,"all");
app.ThicknessMedianEditField.Value = plateMedian;
app.plateThickness();
pause(0.5);
i=i+1;
end
end This is my first time coding in MATLAB and below is my code. The input is from an NI DAQ device, in the form of analog signals. The purpose of the code is to read live data from the hardware (which is attached to sensors), plot the live data real-time (surface plot) and calculate the mean and median of the live data. Currently, the error is
‘Value’ must be a double scalar within the range of ‘Limits’ for the line app.ThicknessMeanEditField.Value = app.plateMeanThickness; and app.ThicknessMedianEditField.Value = plateMedian;,
I have checked the data types of app.plateMeanThickness and plateMedian using class(), and both returns ‘double’. I used Edit Field (Numerical) for app.ThicknessMeanEditField and app.ThicknessMedianEditField, and the limits of both are from -inf to inf. This information is obtained from the Component Browser window, under Limits. I have tried using double() for the variables as well, but the same error still occurs. Therefore, I do not know how to resolve this as both aspects (the data being double scalar and within the range of limits) seem to be satisfied.
as well as Error using -. Arrays have incompatible sizes for this operation. for the line data = abs(z-init);
This line is used to calculate the difference between the initial values of the sensors (init) with the live data (z), which results to the dimension of an object. The source of init and z are exactly the same, with z being a matrix with infinite number of rows and 10 columns, and init being a row vector with the size of 1×10. According to forums, this should be compatible. But I might be wrong. I would really appreciate it if someone can help me solve these errors. I hope I have provided enough information. Thank you for your help in advance.
function readAndPlotSensors(app)
dq = daq("ni");
i1 = addinput(dq,"Dev1","ai8","Voltage");
i1.TerminalConfig = "SingleEnded";
i2 = addinput(dq,"Dev1","ai1","Voltage");
i2.TerminalConfig = "SingleEnded";
i3 = addinput(dq,"Dev1","ai9","Voltage");
i3.TerminalConfig = "SingleEnded";
i4 = addinput(dq,"Dev1","ai2","Voltage");
i4.TerminalConfig = "SingleEnded";
i5 = addinput(dq,"Dev1","ai10","Voltage");
i5.TerminalConfig = "SingleEnded";
i6 = addinput(dq,"Dev1","ai3","Voltage");
i6.TerminalConfig = "SingleEnded";
i7 = addinput(dq,"Dev1","ai11","Voltage");
i7.TerminalConfig = "SingleEnded";
i8 = addinput(dq,"Dev1","ai4","Voltage");
i8.TerminalConfig = "SingleEnded";
i9 = addinput(dq,"Dev1","ai12","Voltage");
i9.TerminalConfig = "SingleEnded";
i10 = addinput(dq,"Dev1","ai5","Voltage");
i10.TerminalConfig = "SingleEnded";
start(dq,"continuous");
init = read(dq, 1, "OutputFormat", "Matrix");
i=0;
i=i+1;
zlim(app.UIAxes, [0 40]);
colormap(app.UIAxes, turbo);
colorbar(app.UIAxes);
while(1)
z = read(dq, "all", "OutputFormat", "Matrix");
data = abs(z-init);
app.dataConv = data*15; %converts data from voltage to mm according to sensor
surf(app.UIAxes, app.dataConv’,"EdgeColor","none");
app.plateMeanThickness = mean(app.dataConv,"all");
app.ThicknessMeanEditField.Value = app.plateMeanThickness;
plateMedian = median(app.dataConv,"all");
app.ThicknessMedianEditField.Value = plateMedian;
app.plateThickness();
pause(0.5);
i=i+1;
end
end ni daq MATLAB Answers — New Questions