Why does this linear function not work while using the data acquisition toolbox

%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.
When the calibrate switch is in noting appears on the graph vs when it is off:
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);

 Respuesta aceptada

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 comentarios

Hi Maneet,
I was able to figure out the for loop part but am having a new issue now relating to the lag in the plotting.
I currently use this function for calibration
function calibratedData = calibrateData(~,data, slopes, intercepts, indices)
% Calibrate the data using slopes and intercepts
calibratedData = data;
for i = 1:max(indices)
calibratedData(:, i) = calibratedData(:, i) * slopes(:, i) + intercepts(:, i);
end
and this function for plotting
function updateLivePlot(app)
% Update the live plot
% Display information for debugging
disp('Debugging Information:');
disp(['LiveAxes class: ', class(app.LiveAxes)]);
disp(['TimestampsFIFOBuffer size: ', num2str(size(app.TimestampsFIFOBuffer))]);
disp(['DataFIFOBufferch1 size: ', num2str(size(app.DataFIFOBufferch1))]);
% Plot the data
plot(app.LiveAxes, app.TimestampsFIFOBuffer, app.DataFIFOBufferch1)
% Adjust the x-axis limits if there's enough data
if numel(app.TimestampsFIFOBuffer) > 1
xlim(app.LiveAxes, [app.TimestampsFIFOBuffer(1), app.TimestampsFIFOBuffer(end)])
end
disableDefaultInteractivity(app.LiveAxes)
end
when I use the disable default interactivity it "fixes" the issue but the colours no longer stay consistent int he plot. Would you know how I could find some middle ground?
Thanks
Hi Conor,
You can post this error as a new question, then I'll be able to help you regarding the same.
Thanks
Hi Maneet,
I have posted it as a new question! Thanks for the help!
Can you please share the question link!
I had someone else answer it! Which fixed it. I am now trying to figure out how to make the code run more smoothly as a whole and add a way to save the data to the workspace so all three channels can be used in the signal analyzer app.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Productos

Versión

R2023b

Preguntada:

el 7 de Feb. de 2024

Comentada:

el 21 de Feb. de 2024

Community Treasure Hunt

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

Start Hunting!

Translated by