Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Slicing an Array

Tags:

arrays

matlab

I am having trouble finding a matlab function to slice an element out of an array.

For example:

A = [1, 2, 3, 4]

I want to take out on element of this array, say the element 3:

B = [1, 2, 4]

Is there a matlab function for this or would I have to code the algorithm to construct a new array with all the elements of A except 3?

like image 347
gprime Avatar asked Jul 14 '26 00:07

gprime


1 Answers

Do this:

index_of_element_to_remove = 3;
A(index_of_element_to_remove) = [];

now A will be [1 2 4]

If you want to remove more elements at the same time you can do:

index_of_element_to_remove = [1 3];
A(index_of_element_to_remove) = [];

now A will be [2 4]

like image 107
memyself Avatar answered Jul 16 '26 14:07

memyself



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!