Error of 'Value' must be a double scalar within the range of 'Limits' and Error using -. Arrays have incompatible sizes for this operation.
6 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 1x10. 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
0 comentarios
Respuestas (1)
Harald
el 13 de Mayo de 2024
Hi,
I am surprised that you report three errors. Are these the result of a single action or possibly of several different actions?
Since this is the first line of your code throwing an error, let's look at Error using - first:
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 1x10. According to forums, this should be compatible.
The information about compatibility is correct. That leads me to think that the information about the dimensions may not be. Are you receiving the error with the first iteration of the while-loop or possibly after some time? Debugging may help track the issue down, particularly with using "Pause on Error", see e.g. here:
The same applies for the other type of error you report. Under the conditions you report, there should not be such error. Thus, I suppose something is or becomes wrong about these conditions. Again, the "Pause on Error" may be helpful.
If this does not help, please try to provide a reproducible example. For the purpose of that, you could use random numbers or data from a .mat file instead of the data acquisition - just anything that we can run as well to see the issue ourselves.
Best wishes,
Harald
0 comentarios
Ver también
Categorías
Más información sobre Get Started with Data Acquisition Toolbox en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!