MATLAB: How to avoid for loop when indexing for loop Hello, I have the following for loop, where pairs(500×10), is there to calculate cc without for loop? for i=1:500cc(i,:)=pairs(i,pairs(i,:));end Best Answer s = size(pairs);index = sub2ind(s, repmat((1:s(1)).', 1, s(2)), pairs) cc = pairs(index) Related SolutionsMATLAB: I have a 720 x 296 matrix, how can I specify for repeat this n times in some kind of loop like: repmat(YourMatrix, n, 1)perhaps? It is not clear what is to be repeated. MATLAB: All possible pairs in a vector Try this:A = [1 2 3 4 5];Out = nchoosek(A, 2)Out = 1 2 1 3 1 4 1 5 2 3 2 4 2 5 3 4 3 5 4 5 Related QuestionWhat would be the way to use one 3D array as index for other 3D arrayHow to apply a function to each column pair of a matrixMerging two arrays based on index arraysUnknown number of output variables
Best Answer