openlang

Totals wrong only for day with one interval (readmatrix? Apple silicon?)

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?

The conversation continues 1

Follow the reasoning
  1. Permalink

    Not readmatrix. cumsum on 1x4 goes along columns. Always give dim:

    total = sum(deltas, 1);

Other sides of the same question

  1. Ported a short MATLAB script to R and one result came back as a matrix

    Hello all, first time porting anything from MATLAB (I've barely touched it), so be gentle. I'm moving a short script from a c…

    Replies 2Latest activity rmatlab
  2. Freezer with zero readings reports status "ok", what am I missing

    My nightly audit script (Rscript, base R) flags freezers whose peak temp is above a limit. Last night U-03's logger was unplu…

    Replies 2Latest activity r
  3. A loop that allocated a column at a time

    Slicing in Julia copies, which I knew and then forgot inside a loop. Take a function that walks the columns of a matrix and d…

    Replies 2Latest activity julia