Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Removing indices from a vector

Subject: Removing indices from a vector

From: Eamonn B

Date: 3 Apr, 2010 15:59:22

Message: 1 of 3

I have a vector set up like this
a = [[5 2 1 4 8]' [6 3 10 3 -5]']; % [x] [y]

I want to delete the x and y at the same time

I am able to show the two indices by doing this
[a(2,1) a(2,2)]

I try and delete them by doing this
[a(2,1) a(2,2)]=[]
I get this error
'Too many output arguments.'

I have also tried this way
z=[a(2,1) a(2,2)]
a(z)=[]
it works
a=1 5 8 10 3 3 6 -5
but it removes the columns thus putting the x and y together which is not what I want.

Anyone know how I can remove the value but still keeping the columns?

Subject: Removing indices from a vector

From: Sadik

Date: 3 Apr, 2010 16:04:05

Message: 2 of 3

Hi Eamonn,

a(2,:) = [];

Best.

Subject: Removing indices from a vector

From: dpb

Date: 3 Apr, 2010 16:13:26

Message: 3 of 3

Eamonn B wrote:
> I have a vector set up like this
> a = [[5 2 1 4 8]' [6 3 10 3 -5]']; % [x] [y]
>
> I want to delete the x and y at the same time
>
> I am able to show the two indices by doing this
> [a(2,1) a(2,2)]
>
> I try and delete them by doing this [a(2,1) a(2,2)]=[]
> I get this error
> 'Too many output arguments.'
>
> I have also tried this way
> z=[a(2,1) a(2,2)]
> a(z)=[]
> it works a=1 5 8 10 3 3 6 -5
> but it removes the columns thus putting the x and y together which is
> not what I want.
>
> Anyone know how I can remove the value but still keeping the columns?

The problem in general is that if you try to remove
more-or-less-randomly placed elements in an array, the array is no
longer square--hence the result above of a vector returned.

You could set elements to zero but to make them null either would
require a cell array or regularizing the elements to be eliminated.

--

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us