Access element of MATLAB multi-dimensional array specified by another vector -
this question has answer here:
- use vector index matrix 3 answers
i have matlab function returns 4-element vector, e.g. [1 2 3 4]
. use function output access corresponding element in existing 4-dimensional vector, i.e. vec(1, 2, 3, 4)
. there way without storing result , explicitly accessing elements, in following?
result = f(blah); myelement = vec(result(1), result(2), result(3), result(4));
in (python-influenced) head, answer looks this:
result = f(blah); myelement = vec(*result); % or vec(tosubscripts(result)); or similar
the *
operator in python expands list comma-separated arguments. there analogous operator or function in matlab solve problem?
there *result
in matlab, it's called comma separated list. unfortunately can not create comma separated list array, conversion cell first required:
result=(num2cell(f(blah))); myelement=v(result{:});
Comments
Post a Comment