How do I make it so my Plot keeps the same colours
显示 更早的评论
I am using a modified version of the live data acquistion that I made. I am having issues dealing with lagging/losing frames on my plot while plotting. After using the
disableDefaultInteractivity(app.LiveAxes);
I can no longer hold the same colours that my variables used to be and they are constantly switching. See below

If I click start + stop the colours then overlay overtop eachother but I am still wanting this to not occur. I have included the relavant code that I am modified from the original example apart from using a table to be able to select multiple channels and a calibration switch that just runs the data through a linear equation.
properties (Access = private)
DAQ % Handle to DAQ object
DAQMeasurementTypes = {'Voltage','IEPE','Audio'}; % DAQ input measurement types supported by the app
DAQSubsystemTypes = {'AnalogInput','AudioInput'}; % DAQ subsystem types supported by the app
DevicesInfo % Array of devices that provide analog input voltage or audio input measurements
TimestampsFIFOBuffer % Timestamps FIFO buffer used for live plot of latest "N" seconds of acquired data
DataFIFOBufferch1 double % Data FIFO buffer used for live plot of latest "N" seconds of acquired data
FIFOMaxSize = 1E+6 % Maximum allowed FIFO buffer size for DataFIFOBuffer and TimestampsFIFOBuffer
int double % int for the calibration
indices double % channels that are selected
calibrate logical % if calibration is turned off and on
data double = zeros(1000000,8); %data before calibration
end
methods (Access = private)
function scansAvailable_Callback(app, src, ~)
% Callback function executed on DAQ object ScansAvailable event
% Check if the app object is still valid
if ~isvalid(app)
return
end
% Read data from the DAQ object
[app.data, timestamps, ~] = read(src, src.ScansAvailableFcnCount, 'OutputFormat', 'Matrix');
% read in slopes&intercepts from the live script
app.sl = evalin('base','slopes');
app.int = evalin('base','intercepts');
% Calibration
if app.calibrate
% calibratedData = double;
calibratedData = calibrateData(app,app.data, app.sl, app.int, app.indices);
else
% If calibration is turned off, use raw data
calibratedData = app.data;
end
% Store continuous acquisition data in FIFO data buffers
buffersize = round(app.DAQ.Rate * app.TimewindowEditField.Value) + 1;
app.TimestampsFIFOBuffer = storeDataInFIFO(app, app.TimestampsFIFOBuffer, buffersize, timestamps);
app.DataFIFOBufferch1 = storeDataInFIFO(app, app.DataFIFOBufferch1, buffersize, calibratedData(:, app.indices));
% Plotting (Update the plot every N data points received)
updatePlotInterval = 10; % Adjust this value based on your preference
if mod(src.ScansAvailableFcnCount, updatePlotInterval) == 0
updateLivePlot(app);
end
end
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
end
function logDataToFile(app, timestamps)
% Log data to file if LogRequested is true
latestdata = [timestamps, app.data]';
fwrite(app.TempFile, latestdata, 'double');
if timestamps(1) == 0
app.TriggerTime = triggertime;
end
end
function updateLivePlot(app)
% Update the live plot
plot(app.LiveAxes, app.TimestampsFIFOBuffer, app.DataFIFOBufferch1)
% Add this line if you want to overlay multiple plots
hold(app.LiveAxes, 'on');
% Disable interactivity
disableDefaultInteractivity(app.LiveAxes);
if numel(app.TimestampsFIFOBuffer) > 1
xlim(app.LiveAxes, [app.TimestampsFIFOBuffer(1), app.TimestampsFIFOBuffer(end)])
end
end
Any Suggestions are greatly appreciated!
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 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!


