MATLAB: How to avoid ‘two for loop’

for loopMATLAB

I don't know how to avoid using for loop, because It takes a lot of time to calculate.
Below is the code to change.
for i = 1 : 26
for j = 1 : 86400
B(86400*(i-1)+j , :) = A(26*(j-1)+i, :);
end
end
I find solutions instead of for loop, like 'repmat' or 'bsxfun', … but I have no ideas how to shorten the time.
Please give me a hand…

Best Answer

How about using a matrix indexing technique as follows:
for i = 1:26
idx_a = 26*((1:86400)-1) + i;
idx_b = 86400*(i-1)+(1:86400);
B(idx_b,:) = A(idx_a,:);
end