Strings have a bit of overhead, but still increase by 2 bytes per character. After every 8 characters, it increases the size of the variable. Red line y=2x+127 .

A picture is created using:
v=[];N=100; for ct = 1:N s=char(randi([0 255],[1,ct])); s=string(s); a=whos('s');v(ct)=a.bytes; end figure(1);clf plot(v) xlabel('# characters') ylabel('# bytes') p=polyfit(1:N,v,1); hold on plot([0,N],[127,2*N+127],'r') hold off
Gelliant
source share