![]() ![]() If you want to combine the indices like having odd row - odd column, and even row - even column, just compute two sets of indices, concatenate them into a single vector and do the same syntax like before. ge returns logical 0 ( false) where A or B have NaN or undefined categorical elements. The test compares only the real part of numeric arrays. Ind = B(1:2:end, 1:2:end) %// For odd rows, odd columns - Change to suit your tastes A > B returns a logical array or a table of logical values with elements set to logical 1 ( true) where A is greater than or equal to B otherwise, the element is logical 0 ( false ). If you want to do this, simply pre-allocate a matrix of zeroes, then copy over those values to extract using the computed indices into the new matrix. Now, given your comment, you want to create a new matrix that will store only these extracted matrix values while making all of the other elements zero. Ind = B(1:2:end, 1:2:end) %// For odd rows, odd columns ![]() ![]() After, use the same logic above to get the actual linear indices: N = numel(A) If you want to determine the actual column major indices to access the matrix, you can generate a vector from 1 to N where N is the total number of elements in your matrix, then reshape this matrix into the desired size that you want. In Matlab I can find all non zero entries in a vector like this: > v 0. It's a bit confusing as your matrix elements are the same as linear indexing values themselves. Syntax: find (X) : Return a vector containing the indices of elements find (X. Accepted Answer: Star Strider I want to find the indices of a matrix and I am using this command. The above assumes that you want the actual matrix values themselves. Odd rows and even columns B = A(1:2:end, 2:2:end) Įven rows and odd columns B = A(2:2:end, 1:2:end) Įven rows and even columns B = A(2:2:end, 2:2:end) If A is an empty 0-by-0 matrix, any (A) returns logical 0 ( false ). It's pretty easy to do with indexing: Odd rows and odd columns B = A(1:2:end, 1:2:end) ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |