This is not a valid statement in matlab:
Y(PartNo)(3:end)
You must either make Y two-dimensional and use this indexing
Y(PartNo, 3:end)
or cut out vector parts and use them directly if you use a loop, as you showed
for PartNo = 1:6 % extract data Y = CD1(1 + 20*(PartNo-1):20*(PartNo),:); % find the second difference Z = Y(3:end) - Y(1:end-2); % mean of absolute value MEAN_ABS_2ND_DIFF_RESULT(PartNo) = mean(abs(Z)); end
Also, since CD1 is a vector, you do not need to index the second dimension. Remove :
Y = CD1(1 + 20*(PartNo-1):20*(PartNo));
Finally, you do not need a loop. You can reshape vector CD1 to a two-dimensional array Y size 20x6 , in which the columns are your parts and work directly with the resulting matrix:
Y = reshape(CD1, 20, 6); Z = Y(3:end,:)-Y(1:end-1,:); MEAN_ABS_2ND_DIFF_RESULT = mean(abs(Z));
source share