matrix-indexing
Indexing of unknown dimensional matrix
For the general case where J can be any length (which I assume always matches the number of dimensions in M), there are a couple options you have: You can place each entry of J in a cell of a cell array using the num2cell function, then create a comma-separated list from this cell array … Read more
How do I remove elements at a set of indices in a vector in MATLAB?
vector(indecies) = [] example: >> a = 1:10; >> a([3,4,7]) = [] a = 1 2 5 6 8 9 10
How can I find the maximum value and its index in array in MATLAB?
The function is max. To obtain the first maximum value you should do [val, idx] = max(a); val is the maximum value and idx is its index.
How to select a submatrix (not in any particular pattern) in Matlab
TLDR: Short Answer As for your question, suppose you have an arbitrary 10-by-10 matrix A. The simplest way to extract the desired sub-matrix would be with an index vector: B = A([1 2 9], [4 6]); Indexing in MATLAB There’s an interesting article in the official documentation that comprehensively explains indexing in MATLAB. Basically, there … Read more
Linear indexing, logical indexing, and all that
In the following I use terminology that I think is more or less in line with standard Matlab practice. However, in some cases I’ve had to sort-of make up a name because I wasn’t aware of an existing one. Please let me know if there are more standard names than those I’m using. This answer … Read more