fork download
  1. @(d,i)sub2ind(d,num2cell(i){:})
  2.  
  3. % to run it:
  4. f=ans;
  5.  
  6. % Dimensions: [5, 10]
  7. % Indices: [4, 2]
  8. % Output: 42
  9. A = zeros(5, 10);
  10. A(4, 2) = 1;
  11. A(f([5, 10], [4, 2]))
  12.  
  13. % Dimensions: [10, 10, 4, 62, 7]
  14. % Indices: [1, 2, 3, 4, 5]
  15. % Output: 22167
  16. A = zeros(10, 10, 4, 62, 7);
  17. A(1, 2, 3, 4, 5) = 1;
  18. A(f([10, 10, 4, 62, 7], [1, 2, 3, 4, 5]))
Success #stdin #stdout 0.44s 121792KB
stdin
Standard input is empty
stdout
ans =

@(d, i) sub2ind (d, num2cell (i) {:})

ans =  1
ans =  1