X = (0:1:42);
figure (1)
plot(X,HZ2,'b--')
It'x X and HZ2 that must be same length -- what does
whos X HX2
show you about the two? We know that X will be 43 elements long, apparently HZ2 is something else instead.
If the point is to plot against ordinal position beginning at the origin instead of one, the general code would be
X = (0:numel(HZ2));
figure (1)
plot(X,HZ2,'b--')
While not really your problem;
Y = readtable('lab5data000.xlsx','Range','E1:AJ43');
HZ = table2array(Y);
HZ1 = HZ';
HZ2 = HZ1(:);
is a whole lot of unneeded machinations -- one could either use table addressing and use the data in Y directly which will already be column-oriented or if one does want an array, use readmatrix instead of readtable