How should I write a code that can realize if a text file is updated and the code updates my plot too?
Show older comments
I have a log file which is keep updating a message (text file attached). This message can somehow be plotted and I have done that (see below) but I don't know how to update my plot when the txt file is updated with a new line?
logfile = uigetfile
opt = detectImportOptions(logfile,'FileType','text','Delimiter',','); % setting import options
opt.VariableNames = {'LogType','RealTimeStamp','DataSet','ParticleTimeStamp','ForcedParticleFlag','TriggerIntensity','Channel2','Channel3','Channel4','Channel5','Channel6','Channel7','Channel8','Channel9','Channel10','Channel11','Channel12','Channel13','Channel14','Channel15','Channel16','Channel17','Channel18','Channel19','Channel20','Channel21','Channel22','Channel23','Channel24','Channel25','Channel26','Channel27','Channel28','Channel29','Channel30','Channel31','Channel32'};
opt.ExtraColumnsRule ='ignore'; % remove extra column
ImportLog = readtable(logfile,opt); % import log file
ImportLog=ImportLog(~any(ismissing(ImportLog),2),:); % import only scattering data and remove other data
ChannelToAngle_T = PHIPS_ChannelToAngle(ImportLog); % channel to angle table
ForcedTrigger = ChannelToAngle_T.ForcedParticleFlag; % forced trigger out of table
idx0 = find(ForcedTrigger == 0); % index of those lines that has forced trigger or not
idx1 = find(ForcedTrigger == 1);
for i= 1:numel(idx0)
Angle = 18:8:170; % Angles
ASF = table2array(ChannelToAngle_T(idx0(end), end-19:end)); % Angular Scattering Function
semilogy(Angle, ASF, 's-','MarkerFaceColor', 'w', 'LineWidth', 2, 'MarkerSize', 10) % plot
hold on
%semilogy(angle, ASF_2, 's--','MarkerFaceColor', 'w', 'LineWidth', 2, 'MarkerSize', 10)
%semilogy(angle, ASF_3, 's--','MarkerFaceColor', 'w', 'LineWidth', 2, 'MarkerSize', 10)
hold off
grid on
xlabel ('Scattering Angle')
ylabel ('Scattering Intensity [cts]')
ylim([0, 5000])
ax = gca;
ax.YAxis(1).Color = 'k'; % change color of LHS y-axis to black
% ax.YAxis(2).Color = 'k'; % change color of RHS y-axis to black
ax.FontSize = 14;
ax.FontWeight = 'bold';
legend('Location', 'southeast')
%
end
Accepted Answer
More Answers (1)
Sepehr Ariaei
on 28 Jun 2021
0 votes
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!