Strangely enough I could not find a general answer for this simple question. The one linked answer here is not general.
sub2ind can be avoided, I believe, with the following equivalence [here]
sub2ind(size(A), row1, row2, row3, row4) is equivalent to
row1+ (row2-1)*size(A,1) + (row3-1)*size(A,1) *size(A,2) + (row4-1)*size(A,1) *size(A,2) *size(A,3).
Meanwhile ind2sub for 2 dimensions (i.e., no row3, row4....) can be avoided as:
i = rem(index-1,size(A,1))+1;
j = (index-i)/size(A,1)+ 1 ;
is equivalent to:
[i,j] = ind2sub(size(A),index);
How do we generalize ind2sub for 3D matrices and so on? I am not interested in debates about whether we should avoid it or not.