I solved my problem by redefining my NaN matrices as a 4x6. I then transversed the matrices after the loop to give me the 6x4 matrix I was looking for.
bars = NaN(4,NoS);
errors = NaN(4,NoS);
for i=1:NoS*NoJ
clear ave stdev
ave = mean(data((i*NoJ)-3:(i*NoJ),3));
stdev = std(data((i*NoJ)-3:(i*NoJ),3));
bars(i) = ave;
errors(i) = stdev;
end
bars1 = bars'
stdev1 = stdev'
If anyone knows any more efficient ways of doing this then please let me know!