I have an n x m matrix. I want to extract each column and do some operations, say 2D interpolation of each column to different grids, and then replace corresponding columns with the new data. How can I do it in a loop?
One way that is scalable and matches your example:
A(indx + (0:size(indx,2)-1)*size(A,1))
This uses implicit expansion. On earlier versions of MATLAB you would have to use bsxfun or repmat to get the same result.
Should work as long as indx columns match the columns of A that you want extracted. If not, then you would need to modify the row indexing vector I used to match the actual column indexing you wanted.
Best Answer