When I am using A(:,9)= [ ]; for deletion, an error is shown (Matrix index is out of range for deletion.). What might the problem be?
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Chandvi Arora
am 18 Jul. 2017
Beantwortet: Walter Roberson
am 18 Jul. 2017
The matrix in which I have to perform deletion is 1*18. how can I perform deletion of elements from 9-18 if A(:,9)= [ ];(This is particularly for 9th element) is wrong?
0 Kommentare
Akzeptierte Antwort
Akira Agata
am 18 Jul. 2017
If the size your numeric array A is 1x18, simply A(9:18) = []; will delete 9th~18th elements from the array.
0 Kommentare
Weitere Antworten (1)
Walter Roberson
am 18 Jul. 2017
If you are looping through a matrix doing tests and deleting rows (or columns) then what would look to be the obvious approach will result in errors. After you delete an entry, the ones after it "fall down" to fill the gap, like Tetris blocks. Then the matrix becomes smaller, so if it was 16 before then it becomes only 15 now and your loop to 16 now is going to fail when it tries to index item 16 (which fell down to 15....)
The easy work around for this is to start at the end of the array and loop backwards to the beginning.
0 Kommentare
Siehe auch
Kategorien
Mehr zu Resizing and Reshaping Matrices finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!