1

Given a multidimensional array A = MxMxMx...xM, where ndims(A)=n and the subscript array b=[a1, a2, ..., an]. How to get A(a1, a2, a3, ..., an)? I've tried A(b). It's not a correct way. And a correct way is to write a function to convert the subscript array to the index, saying i, and then we can use A(i) to get what I want. Is there an easier way?

Thanks

1 Answer 1

1

I think that, the easiest way would be through linear indexing, using, e.g. sub2ind function.

BasCell = num2cell(b);    
i = sub2ind(size(A), BasCell{:});
A(i); % access ith element in A, using linear indexing
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.