How to remove the third to last element of an array?
Mostra commenti meno recenti
Hello,
If I have an array of random numbers (e.g. number = [2; 3; 4; 5; 10; 0.45; . . . 3; 99; 294; 1.96] ), how can I remove the third to last value (99)? I need to remove it idependent of the value. I know how to remove the first element ( number(1) = [] ) and the last value ( number(end) = [] ), but I am not sure how to remove the position of the 99.
Does someone know how to do that? Any help will be appreciated.
Thanks,
Guilherme
2 Commenti
Guilherme de Melo
il 31 Ott 2023
Spostato: John D'Errico
il 31 Ott 2023
John D'Errico
il 31 Ott 2023
Please don't add an answer you to ask a question, even to your own question.
But, yes, if you wanted to remove specific elements, counting from the end backwards, you could use that scheme. Just define k to be the offset, or even multiple offsets from the end.
Risposta accettata
Più risposte (1)
% put the index to be removed in paranthesis, if you want to remove 99th
% index, put 99, otherwise you can use 'end' to mean 'length(a)' so 'end-1'
% would mean 1 before the last index
a = [1 2 3 4 5 6 7 8 9 0]; % array
a(end-2) = []; % remove '8' from the array
a
Categorie
Scopri di più su Creating and Concatenating Matrices in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!