By using for loop command take values from several matrices to build a new matrix in matlab<>
This question already has an answer here:
You don't need for loop for this. What you want to achieve is to interleave two matrices, you can do it manually
C = [A(:, [1 2]), B(:, [1 2]), A(:, [3 4]), B(:, [3 4])];
Or you can make it into a more general solution:
function out = interleave(m1, m2, step) out = [reshape(m1, [numel(m1)/step step]); reshape(m2, [numel(m2)/step step])]; out = reshape( out, [size(m1,1) numel(out)/size(m1,1)]); end
C = interleave(A,B,2)
will give you the result you want.