How do i re-insert an element into an array?
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
A.K
el 17 de Jun. de 2016
Respondida: Image Analyst
el 17 de Jun. de 2016
My original array was A=[1 5 3 7 8 2]. I deleted some elements and the array became A=[1 3 7 8]. The elements I deleted are stored in the array DEL=[5 2] and the indexes they were deleted from are stored in the array INDX=[2 6].
How do I Insert the deleted elements back into array 'A' in their original indexes?
0 comentarios
Respuesta aceptada
Image Analyst
el 17 de Jun. de 2016
Try this:
% A=[1 5 3 7 8 2]. I deleted some elements and the array became
A=[1 3 7 8]
% The elements I deleted are stored in the array
DEL=[5 2]
% and the indexes they were deleted from are stored in the array
INDX=[2 6]
for k = 1 : length(DEL)
A = [A(1:INDX(k)-1), DEL(k), A(INDX(k):end)];
end
A % Print to command window.
0 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Matrix Indexing en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!