I have the following problem:
I have metrics given, we say that 4x4
. How do I get an index of the following combinations:
- Row strange and column strangely
- Row strange and column
- Row and even weird columns
- Even columns and columns
For example if I have the matrix:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 - 'Rows Strange and Odd Columns' will be indexes of 1, 3, 9, 11 ...
- 'Row strange and column too' The indexes of 2, 4, 10, 12 will be ...
- 'Rows and Columns Strange' 5, 7, 13, 15 Will be. .
- And the 'row and column also' will be 6, 8, 14, 16 indexes ...
Also, is it possible to add those functions? For example, do I get an index for the 'row strangest and odd column' and 'row and column too'?
Thank you!
It is very easy to do with indexing:
odd lines and weird columns < / H1> B = A (1: 2: end, 1: 2: end);
Strange rows and even columns
B = A (1: 2: end, 2: 2: end);
Even rows and weird columns
b = a (2: 2: end, 1: 2: end);
Even rows and columns
B = A (2: 2: end, 2: 2: end);
It is assumed above that you want real matrix value to yourself. It's a little misleading because your matrix elements are the same, as the linear indexing value itself is. If you want to set the main column key index to reach the matrix, you can generate a vector from 1 to N
where N
is the total of elements of your matrix If there is a number, then this matrix will again get the desired shape in the shape you want. After this, use the above given argument to get the actual linear index:
N = numel (A); B = reshape (1: n, size (a, 1), shape (a, 2)); IND = B (1: 2: end, 1: 2: end); For% // strange lines, weird columns%% repeat for others ...
Now, your comment has been given, you just want to create a new matrix which The result will be matrix value, while all other elements make zero. If you want to do this, then assign a matrix of zero first, then copy those values, which are extracted into new matrix using computed indices. In other words:
N = numel (A); B = reshape (1: n, size (a, 1), shape (a, 2)); IND = B (1: 2: end, 1: 2: end); For Strange Rows, Strange Columns - Replace With Your Taste = Zero (Size (A)); Out (IND (:)) = A (IND (:));
If you want to mess around the index such as weird rows - weird columns, and even line - even columns, calculate only two sets, in a vector Add and do the same syntax as before: therefore
N = numel (A); B = reshape (1: n, size (a, 1), shape (a, 2)); IND = B (1: 2: end, 1: 2: end); For% // strange lines, weird column ind 2 = b (2: 2: end, 2: 2: end); % // Even for rows, even column ind [= (Ind (:); ind2 (:)]; out = zero (size (a)); out (ind) = A ( IND);
Comments
Post a Comment