Small MATLAB report for electricity meters, one CSV per day, columns = meters, rows = 30 min intervals. Run it with matlab -batch run_report from Neovim terminal. Finance wants it today, so I am not in good mood.
2026-10-30 has 3 intervals and numbers are right. 2026-10-31 has only one interval, gateway was down most of the day:
M101,M102,M103,M104
0.44,0.30,1.05,0.05
Total kWh for this day prints [0.44 0.74 1.79 1.84]. Cost is wrong the same way, growing from left to right. Total should be just the four numbers from the row. peak_kwh and n_intervals are correct, so something is off only in totals.
function report = meter_report(deltas, cfg)
running = cumsum(deltas);
report.total_kwh = running(end, :);
report.cost = report.total_kwh * cfg.tariff;
report.peak_kwh = max(deltas, [], 1);
report.n_intervals = size(deltas, 1);
end
batches{k} = readmatrix(fullfile(dataDir, names{k}));
size(batches{k}) gives 1x4, so file is read fine. I suspect readmatrix does something strange with header plus one data line (docs), or this native Apple silicon build behaves differently. Nobody ran this on another machine yet. I tried format long, restarting MATLAB, deleting the header. Nothing changed.
Sorting of files is by natsortfiles from standard library, so that is not the problem.
Why only this day? Same code, same format. Anyone seen this?