Borrar filtros
Borrar filtros

All index values expect certain indices

2 visualizaciones (últimos 30 días)
Niels de Vries
Niels de Vries el 27 de Nov. de 2018
Respondida: Bruno Luong el 27 de Nov. de 2018
Hey all,
My question is as follows: how can i select all the index values except for certain indices. Let's consider the following example:
A = [5 6 7 8]
x{1} = [1];
x{2} = [1 2];
x{3} = [2 3 4];
Now i want to select the values of A except for the indices in x, so the output should be:
[6 7 8]
[7 8]
[5]
I tried the following code (which does not work), does someone knows how to do this ?
for i = 1:3
A(1:end ~= x{i})
end
Thanks in advance

Respuesta aceptada

Bruno Luong
Bruno Luong el 27 de Nov. de 2018
A = [5 6 7 8];
x{1} = [1];
x{2} = [1 2];
x{3} = [2 3 4];
c = cellfun(@(i) A(setdiff(1:end,i)), x, 'unif', 0)
c{:}
That gives:
ans =
6 7 8
ans =
7 8
ans =
5

Más respuestas (0)

Categorías

Más información sobre Matrix Indexing en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2017b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by