Thanks! Create a function that takes in a 1 row array and removes a scalar or ch
ID: 3553301 • Letter: T
Question
Thanks!
Create a function that takes in a 1 row array and removes a scalar or character value from it anywhere that it appears shortening the array. Function name: remove_value Signature [array_out, len] = remove_value(array_in, value) You do not have to use the variable names array_out, len, arrayjn, value 1st input argument: array with elements to be removed = [0 2314560132214 2] 2nd input argument: element value to be removed = 2 Is' output argument: array with elements removed = [0 3145601314] 2nd output argument: number of elements removed = 4Explanation / Answer
Subject: removing multiple elements from an array
From: alayi
Date: 21 May, 2007 16:48:51
Message: 1 of 9
If I have a 1-D array and a variable length list of indices to be
removed, what is the simplest, cleanest approach to remove those
elements?
Thanks.
Subject: removing multiple elements from an array
From: Jos
Date: 21 May, 2007 16:58:36
Message: 2 of 9
alayi wrote:
<SNIP howto remove items
A = 1:10 ; % 1-D array
ind = [1 4 7] ; % indices to be removed
A(ind) = [] ; % remove
hth
Jos
Subject: removing multiple elements from an array
From: cPasFort
Date: 21 May, 2007 17:17:45
Message: 3 of 9
"Jos" <x@y.z> wrote in message news:ef57aa2.0@webcrossing.raydaftYaTP...
> alayi wrote:
> <SNIP howto remove items
>
> A = 1:10 ; % 1-D array
> ind = [1 4 7] ; % indices to be removed
> A(ind) = [] ; % remove
>
> hth
> Jos
Wow! Surprise for me...
Subject: removing multiple elements from an array
From: alayi
Date: 22 May, 2007 08:30:11
Message: 4 of 9
I didn't think it would be so easy to remove items without shifting
the indices! Thank you.
Subject: removing multiple elements from an array
From: Greg von Winckel
Date: 22 May, 2007 08:42:17
Message: 5 of 9
One other possible solution
A=A(setdiff(1:length(A),ind));
where ind is the vector of elements you want to discard.
HTH,
Greg
gregory-von,winckel&uni-graz,at
alayi wrote:
>
>
> I didn't think it would be so easy to remove items without shifting
> the indices! Thank you.
Subject: removing multiple elements from an array
From: Erica B
Date: 26 Jun, 2009 08:25:03
Message: 6 of 9
"Greg von Winckel" <see@signature.com> wrote in message <ef57aa2.3@webcrossing.raydaftYaTP>...
> One other possible solution
>
> A=A(setdiff(1:length(A),ind));
>
> where ind is the vector of elements you want to discard.
>
> HTH,
>
> Greg
>
> gregory-von,winckel&uni-graz,at
>
> alayi wrote:
> >
> >
> > I didn't think it would be so easy to remove items without shifting
> > the indices! Thank you.
Oh that is clever and EXACTLY what I needed. Thank you!!
Erica
Subject: removing multiple elements from an array
From: Shar
Date: 24 Jun, 2010 17:15:24
Message: 7 of 9
Why is this better than the [] deletion method?
Thanks!
"Erica B" <ebickford@wisc.edu> wrote in message <h220kv$5rd$1@fred.mathworks.com>...
> "Greg von Winckel" <see@signature.com> wrote in message <ef57aa2.3@webcrossing.raydaftYaTP>...
> > One other possible solution
> >
> > A=A(setdiff(1:length(A),ind));
> >
> > where ind is the vector of elements you want to discard.
> >
> > HTH,
> >
> > Greg
> >
> > gregory-von,winckel&uni-graz,at
> >
> > alayi wrote:
> > >
> > >
> > > I didn't think it would be so easy to remove items without shifting
> > > the indices! Thank you.
>
> Oh that is clever and EXACTLY what I needed. Thank you!!
>
> Erica
Subject: removing multiple elements from an array
From: mehmet
Date: 3 Feb, 2013 08:31:07
Message: 8 of 9
Jos <x@y.z> wrote in message <ef57aa2.0@webcrossing.raydaftYaTP>...
> alayi wrote:
> <SNIP howto remove items
>
> A = 1:10 ; % 1-D array
> ind = [1 4 7] ; % indices to be removed
> A(ind) = [] ; % remove
>
> hth
> Jos
thanks
Subject: removing multiple elements from an array
From: alayi
Date: 21 May, 2007 16:48:51
Message: 1 of 9
Reply to this message Add author to My Watch List View original format Flag as spamIf I have a 1-D array and a variable length list of indices to be
removed, what is the simplest, cleanest approach to remove those
elements?
Thanks.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.