I have a question regarding indexing and loops in MATLAB. I have a vector of length n (named data in the code below). I want to examine this vector 4 elements at a time inside of a for loop. How can I do this? My attempt included below does not work because it will exceed the array dimensions at the end of the loop.
for k = 1:length(data) index = k:k+3; cur_data = data(index); pre_q_data1 = cur_data(1); pre_q_data2 = cur_data(2); % Interweaving the data q = [pre_q_data1; pre_q_data2]; qdata = q(:)'; pre_i_data1 = cur_data(3); pre_i_data2 = cur_data(4); i = [pre_i_data1; pre_i_data2]; idata = i(:)'; end
k+3is equal to the last index of the array, not when it's equal toend+3.for-loopand usebufferinstead. See here.bufferinstead if you have the signal processing toolbox"