Say that we have a 3x3 matrix in matlab. If we type x(:), this will select all the elements in the matrix, right?
How can we select all the elecments except element x(2,2)? What should we type in this case?
Thanks.
Say that we have a 3x3 matrix in matlab. If we type x(:), this will select all the elements in the matrix, right?
How can we select all the elecments except element x(2,2)? What should we type in this case?
Thanks.
I would do it like this: first, create a logical array of trues, which would select all elements if used as an index mask:
mask = true(size(x) );
Now set element 2,2 to be false, therefore deselecting it:
mask(2,2) = false;
Now use this mask to select elements from x:
myValues = x(mask);
EDIT: Removed second, incorrect answer.
You could use:
A(setdiff(1:numel(A),ceil(numel(A)/2)))
For example, for the input as:
>> A = randi(100,3)
A =
49 71 68
45 76 66
65 28 17
The output is:
>> A(setdiff(1:numel(A),ceil(numel(A)/2)))
ans =
49 45 65 71 28 68 66 17