Find and remove a value from an array
73 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Zenia Askar
el 12 de En. de 2020
Comentada: Zenia Askar
el 14 de En. de 2020
Hello! I'm trying to find in an array 'done' the position of a value 'next' without the use of a loop. Then, in this array i want to remove from that position found, the existing element.
out=find(done==next);
done(out)=[];
I tried it this way but is doesnt seem to work. Would you find an arror or recommend another way?
0 comentarios
Respuesta aceptada
Robert U
el 13 de En. de 2020
Editada: Robert U
el 13 de En. de 2020
Hi Zenia Askar,
Assuming the content of your variables 'done' and 'next' are numeric your code cannot remove a single value from the matrix without destroying the matrix structure. You should apply logical indexing rather than using 'find()'.
done(done == next) = [];
The result does not represent the matrix structure anymore but is a vector then. To omit that you can place a NaN-value instead.
done(done == next) = NaN;
Kind regards,
Robert
Más respuestas (0)
Ver también
Categorías
Más información sobre Matrices and Arrays en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!