function ax = plotRgaData(tbl, tStart, tEnd) %PLOTRGADATA Plot RGA partial pressures vs time (companion to plotCryoData). % % ax = plotRgaData(tbl, tStart, tEnd) % Plots every channel column of an rgaImportData table against its shared % datetime axis. tStart/tEnd (datetime) optionally subset the range, just % like plotCryoData. Returns a struct with the axes handle. % % By default the y-axis is linear (RGA scans contain small near-noise % negatives that a log axis cannot show). To switch to the classic % semilog view afterwards: % set(ax.partial, 'YScale', 'log'); % (values <= 0 are simply not drawn on a log axis). % % EXAMPLE % tbl = rgaImportData('rga1_Jul_01_2026_08-23-06_AM.txt'); % ax = plotRgaData(tbl); % ax = plotRgaData(tbl, t1, t2); % zoom to a window % % See also RGAIMPORTDATA, PLOTCRYODATA %--- Extract datetime column --- dt = tbl.datetime; %--- If start/stop provided, subset the table --- if nargin >= 3 && ~isempty(tStart) && ~isempty(tEnd) mask = dt >= tStart & dt <= tEnd; tbl = tbl(mask, :); dt = dt(mask); end %--- Channel columns = everything except datetime & time_s --- chVars = setdiff(tbl.Properties.VariableNames, {'datetime','time_s'}, 'stable'); units = 'a.u.'; if isfield(tbl.Properties.UserData, 'units') units = tbl.Properties.UserData.units; end %--- Plot --- figure; tl = tiledlayout(1, 1); tl.TileSpacing = 'compact'; tl.Padding = 'compact'; ax.partial = nexttile; hold on; for k = 1:numel(chVars) plot(dt, tbl.(chVars{k}), '-', 'LineWidth', 1, ... 'DisplayName', prettyName(chVars{k})); end grid on; ylabel(sprintf('Partial pressure [%s]', units)); xlabel('Date & Time'); title('RGA partial pressures'); legend('Location', 'best', 'Interpreter', 'none'); % Match plotCryoData's datetime tick style ax.partial.XAxis.TickLabelFormat = 'dd-MMM HH:mm'; end % ------------------------------------------------------------------------- function s = prettyName(v) % "Water_m18" -> "Water (m18)" s = regexprep(v, '_m(\d+)$', ' (m$1)'); s = strrep(s, '_', ' '); end