Why does this linear function not work while using the data acquisition toolbox
조회 수: 2 (최근 30일)
이전 댓글 표시
%if the calibration switch is turned on use the slopes and
% intercepts read in above
if app.calibrate == true
while i < numel(app.indices)
i = i + 1;
data(:,i) = data(:,i)*slope(:,i)+intercepts(:,i);
end
% if the calibration switch is turned off then just display data as Voltage
elseif app.calibrate == false
data = data*1 + 0;
end
I read in the slopes and intercepts calculated in the workspace and read it in using evalin.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1610616/image.png)
When the calibrate switch is in noting appears on the graph vs when it is off:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1610621/image.png)
I also know that if i replace i with any whole number it will work and correspond with the correct channels slope and intercept.
data(:,1) = data(:,1)*slope(:,1)+intercepts(:,1);
댓글 수: 0
채택된 답변
Maneet Kaur Bagga
2024년 2월 20일
Hi,
As per my understanding, you created the "Calibrate" switch in the App Designer for Live Data Acquisition and defined a callback for the switch with the conditions mentioned in the code above. Also, it is mentioned that on changing the value of "i" to a whole number the switch is working correctly.
One of the possible workaround for the array could be to initialize the variable "i" before the loop starts, ensuring that the loop is running from the beginning of the "app.indices" array. Please check if "app.indices" is defined and is not empty.
Also, as multiple channels are calibrated you are incrementing "i" in the while loop, therefore it can be replaced by a "for" loop as it will avoid to manually initialize and increment and the loop control statement will handle it automatically.
Please refer to the code snippet below for better understanding:
if app.calibrate == true
for i = 1:numel(app.indices)
data(:,i) = data(:,i) * slope(:,i) + intercepts(:,i);
end
plotGraph(app, data);
elseif app.calibrate == false
plotGraph(app, data);
end
Hope this helps!
댓글 수: 5
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 National Instruments Frame Grabbers에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!