MATLAB: How to access the elements of one array with another array

arrayMATLAB

I'd like to assign elements to an array in the following manner:
a = zeros(2,2,2);
ix=1;
iy=1;
b = [1,1];
a([ix,iy],:) = b(:)
Where ix and iy represent the position in the 1st and 2nd directions, a in it's 3rd dimension and b are the same length length. For my application ix and iy really need to be in the same array and the method needs to be applicable to N-dimensions. Is there a way to do such an assignment?

Best Answer

This is really very easy once you put those indices into a cell array:
C = {ix,iy,...,iN,':'};
a(C{:}) = b
Given a numeric vector of indices V:
V = [ix,iy,...,iN];
C = num2cell(V);
a(C{:},':') = b;
or
a(C{:},:) = b;