How do I make it so my Plot keeps the same colours
43 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
採用された回答
Jonas
2024 年 2 月 21 日
for me this looks like an error that has nothing to do with the disableDefaultInteraction
using
% plot(app.LiveAxes, app.TimestampsFIFOBuffer, app.DataFIFOBufferch1)
% hold(app.LiveAxes, 'on');
repeatedly for updating makes the color jump to the next color each time after calling plot (since you used hold on to keep adding data);
if you dont want to change the color, specify it explicitly with the 'Color' Name-Value pair during the plot command?
if your plot data has mutiple columns, the you can either plot each col inidividually with the needed color, or you set the color index for the next color
% example for three channels
data1=[1:10;2:11;3:12]';
data2=[10:-1:1;11:-1:2;12:-1:3]';
% example for wrong coloring
figure;
plot(1:10,data1);
hold on;
plot(10:19,data2);
% example for right coloring
figure;
plot(1:10,data1);
hold on;
ax=gca;
ax.ColorOrderIndex=1;
plot(10:19,data2);
7 件のコメント
Jonas
2024 年 2 月 22 日
concerning the multi channel recording and plotting, i ask myself why you even have to worry about plot colors. those are already implemented in most of the case. Without searching, I remember an app on file exchange called DAQx, which is exactly the same as you are coding, a multi channel recording app. I have programmed a similar app privatly, which is based on the same app as you are modifying.
concerning the set line you were asking for
set(p(lineNr),'XData',[oldXData,dataX2(:,lineNr)'],'YData',[oldYData,dataY2(:,lineNr)']);
each line object (here p), has stored style information etc. and also the plotting x and y data stored with it. adding the new data to the vector XData and YData, you tell make the line longer. since you have for each channel one line object, we have to add the correct channel of the new data (dataX2 and dataY2) to their respective line object
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Analog Data Acquisition についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!