Search All of the Math Forum:
Views expressed in these public forums are not endorsed by
Drexel University or The Math Forum.



Quick subscript resolution
Posted:
Jul 15, 1996 6:30 AM


At various times in programs I want to subscript a matrix A with two index vectors u and v which are generated by the program. What I want is a function which ensures that if either u or v is capable of being interpreted as a logical subscript and an indexed subscript it is interpreted as indexed. For example if A = magic(3) I'd like a function B = take(A,u,v) which returns A(u,v) except that take(A,[1 1 1],1:3) should return [8 1 6; 8 1 6; 8 1 6] rather than A.
Of course if MATLAB resolved ambiguities the other way, i.e. assumed that ambiguous subscripts were indexed, and someone required them to be interpreted as logical by default it would be easy: just surround the subscript by a find(...). But all my attempts to program it this way involve ugly if loops etc. Am I missing something, is there even a way to do it without the function call?
Matthew Wright Institute of Sound and Vibration Research University of Southampton



