Thread Subject: Deleting cells

Subject: Deleting cells

From: Ali Hussain

Date: 17 Jun, 2008 09:15:05

Message: 1 of 9

Hello,

I have a problem, it may be simple but im cant figure out
how to delete cells in a large matrix.

For example.
-5 -1 -5 -1 -5
-4 -4 -4 -4 -4
-3 -3 -3 -3 -3
-2 -2 -2 -2 -2
-1 -1 -1 -1 -1
0 0 0 0 0
1 1 1 1 1
2 2 2 2 2
3 3 3 3 3
4 3 4 3 4
5 1 5 1 5



If the above is a matrix and I am trying to delete cells
and their corresponding rows with values out of the range
of (-3 < A < 3). I have tried
 A= [The above Matrix}
q=find(sum((A)>3));
A(q:end)=[];
 

But the above deletes all the matrix.
I have tried the below to find the first occurrence.

>> q=find(A>3,1)
A(q,:)=[]

But this only deletes one row and gives the below answer.

-5 -5 -5 -5 -5
-4 -4 -4 -4 -4
-3 -3 -3 -3 -3
-2 -2 -2 -2 -2
-1 -1 -1 -1 -1
0 0 0 0 0
1 1 1 1 1
2 2 2 2 2
3 3 3 3 3
5 5 5 5 5



What I am finally trying to achieve is the below matrix.

-3 -3 -3 -3 -3
-2 -2 -2 -2 -2
-1 -1 -1 -1 -1
0 0 0 0 0
1 1 1 1 1
2 2 2 2 2
3 3 3 3 3


Thanks


Subject: Deleting cells

From: French Caro

Date: 17 Jun, 2008 09:28:02

Message: 2 of 9

"Ali Hussain" <hussaizj@aston.ac.uk> wrote in message
<g37vap$81f$1@fred.mathworks.com>...
> Hello,
>
> I have a problem, it may be simple but im cant figure out
> how to delete cells in a large matrix.
>
> For example.
> -5 -1 -5 -1 -5
> -4 -4 -4 -4 -4
> -3 -3 -3 -3 -3
> -2 -2 -2 -2 -2
> -1 -1 -1 -1 -1
> 0 0 0 0 0
> 1 1 1 1 1
> 2 2 2 2 2
> 3 3 3 3 3
> 4 3 4 3 4
> 5 1 5 1 5
>
>
>
> If the above is a matrix and I am trying to delete cells
> and their corresponding rows with values out of the range
> of (-3 < A < 3). I have tried
> A= [The above Matrix}
> q=find(sum((A)>3));
> A(q:end)=[];
>
>
> But the above deletes all the matrix.
> I have tried the below to find the first occurrence.
>
> >> q=find(A>3,1)
> A(q,:)=[]
>
> But this only deletes one row and gives the below answer.
>
> -5 -5 -5 -5 -5
> -4 -4 -4 -4 -4
> -3 -3 -3 -3 -3
> -2 -2 -2 -2 -2
> -1 -1 -1 -1 -1
> 0 0 0 0 0
> 1 1 1 1 1
> 2 2 2 2 2
> 3 3 3 3 3
> 5 5 5 5 5
>
>
>
> What I am finally trying to achieve is the below matrix.
>
> -3 -3 -3 -3 -3
> -2 -2 -2 -2 -2
> -1 -1 -1 -1 -1
> 0 0 0 0 0
> 1 1 1 1 1
> 2 2 2 2 2
> 3 3 3 3 3
>
>
> Thanks
>
>
Hi
Maybe this would work :
idx=abs(max(A,[],1))>3;
A(idx,:)=[]

Caroline

Subject: Deleting cells

From: Piter_

Date: 17 Jun, 2008 09:48:51

Message: 3 of 9

A=[ -5 -1 -5 -1 -5; ...
    -4 -4 -4 -4 -4; ...
   -3 -3 -3 -3 -3; ...
 -2 -2 -2 -2 -2; ...
 -1 -1 -1 -1 -1; ...
 0 0 0 0 0; ...
 1 1 1 1 1; ...
 2 2 2 2 2; ...
 3 3 3 3 3; ...
 4 3 4 3 4; ...
 5 1 5 1 5];
%note that
%sum(A)
%
%ans =
%
% 0 -1 0 -1 0
% sum(A,2)
%
% ans =
%
% -17
% -20
% -15
% -10
% -5
% 0
% 5
% 10
% 15
% 18
% 17

% save what you need, not delete what u don't
q=find((sum(A,2)>=-15) & (sum(A,2)<=15))

A=A(q,:)

Subject: Deleting cells

From: Ali Hussain

Date: 17 Jun, 2008 10:11:02

Message: 4 of 9

"French Caro " <caro95470@nospam.free.fr> wrote in message
<g38032$ed3$1@fred.mathworks.com>...
> "Ali Hussain" <hussaizj@aston.ac.uk> wrote in message
> <g37vap$81f$1@fred.mathworks.com>...
> > Hello,
> >
> > I have a problem, it may be simple but im cant figure
out
> > how to delete cells in a large matrix.
> >
> > For example.
> > -5 -1 -5 -1 -5
> > -4 -4 -4 -4 -4
> > -3 -3 -3 -3 -3
> > -2 -2 -2 -2 -2
> > -1 -1 -1 -1 -1
> > 0 0 0 0 0
> > 1 1 1 1 1
> > 2 2 2 2 2
> > 3 3 3 3 3
> > 4 3 4 3 4
> > 5 1 5 1 5
> >
> >
> >
> > If the above is a matrix and I am trying to delete
cells
> > and their corresponding rows with values out of the
range
> > of (-3 < A < 3). I have tried
> > A= [The above Matrix}
> > q=find(sum((A)>3));
> > A(q:end)=[];
> >
> >
> > But the above deletes all the matrix.
> > I have tried the below to find the first occurrence.
> >
> > >> q=find(A>3,1)
> > A(q,:)=[]
> >
> > But this only deletes one row and gives the below
answer.
> >
> > -5 -5 -5 -5 -5
> > -4 -4 -4 -4 -4
> > -3 -3 -3 -3 -3
> > -2 -2 -2 -2 -2
> > -1 -1 -1 -1 -1
> > 0 0 0 0 0
> > 1 1 1 1 1
> > 2 2 2 2 2
> > 3 3 3 3 3
> > 5 5 5 5 5
> >
> >
> >
> > What I am finally trying to achieve is the below matrix.
> >
> > -3 -3 -3 -3 -3
> > -2 -2 -2 -2 -2
> > -1 -1 -1 -1 -1
> > 0 0 0 0 0
> > 1 1 1 1 1
> > 2 2 2 2 2
> > 3 3 3 3 3
> >
> >
> > Thanks
> >
> >
> Hi
> Maybe this would work :
> idx=abs(max(A,[],1))>3;
> A(idx,:)=[]
>
> Caroline



Hi,

I have tried the above code and it worked only when I
changed the dimension from 1 to 2(as in the code below).
Is there a way that this can be changed so i can
automatically specify the dimension as its used for a
1024x168 double matrix.

>> idx=abs(max(Sheet1,[],2))>3;
>> Sheet1(idx,:)=[]

Thanks

Subject: Deleting cells

From: French Caro

Date: 17 Jun, 2008 10:24:02

Message: 5 of 9

"Ali Hussain" <hussaizj@aston.ac.uk> wrote in message
<snip>
>
> Hi,
>
> I have tried the above code and it worked only when I
> changed the dimension from 1 to 2(as in the code below).
> Is there a way that this can be changed so i can
> automatically specify the dimension as its used for a
> 1024x168 double matrix.
>
> >> idx=abs(max(Sheet1,[],2))>3;
> >> Sheet1(idx,:)=[]
>
> Thanks

Yes I was not sure of the third argument.
What do you mean by "Is there a way that this can be changed
so i can automatically specify the dimension" ?

In this formula the dimension is not used.
It will work for any N*M matrix.
The 2 in max(A,[],2) just indicates the dimension along
where max is done (not sure I'm very clear on this sorry)

Caroline

Subject: Deleting cells

From: Ali Hussain

Date: 17 Jun, 2008 10:30:32

Message: 6 of 9

"French Caro " <caro95470@nospam.free.fr> wrote in message
<g383c2$938$1@fred.mathworks.com>...
> "Ali Hussain" <hussaizj@aston.ac.uk> wrote in message
> <snip>
> >
> > Hi,
> >
> > I have tried the above code and it worked only when I
> > changed the dimension from 1 to 2(as in the code
below).
> > Is there a way that this can be changed so i can
> > automatically specify the dimension as its used for a
> > 1024x168 double matrix.
> >
> > >> idx=abs(max(Sheet1,[],2))>3;
> > >> Sheet1(idx,:)=[]
> >
> > Thanks
>
> Yes I was not sure of the third argument.
> What do you mean by "Is there a way that this can be
changed
> so i can automatically specify the dimension" ?
>
> In this formula the dimension is not used.
> It will work for any N*M matrix.
> The 2 in max(A,[],2) just indicates the dimension along
> where max is done (not sure I'm very clear on this sorry)
>
> Caroline

I have tried it again with adding extra rows of data. I
see what it means by dimension(of the matrix).

Thanks again


Subject: Deleting cells

From: Ali Hussain

Date: 17 Jun, 2008 14:27:02

Message: 7 of 9

> > Hi,
> >
> > I have tried the above code and it worked only when I
> > changed the dimension from 1 to 2(as in the code
below).
> > Is there a way that this can be changed so i can
> > automatically specify the dimension as its used for a
> > 1024x168 double matrix.
> >
> > >> idx=abs(max(Sheet1,[],2))>3;
> > >> Sheet1(idx,:)=[]
> >
> > Thanks
>
> Yes I was not sure of the third argument.
> What do you mean by "Is there a way that this can be
changed
> so i can automatically specify the dimension" ?
>
> In this formula the dimension is not used.
> It will work for any N*M matrix.
> The 2 in max(A,[],2) just indicates the dimension along
> where max is done (not sure I'm very clear on this sorry)
>
> Caroline

Hi,

Thank you for the response...

I am also trying to do the same for another matrix

-5 -4 -3 -2 -1 0 1 2 3 4 5
-1 -4 -3 -2 -1 0 1 2 3 4 5
-5 -4 -3 -2 -1 0 1 2 3 4 5
-1 -4 -3 -2 -1 0 1 2 3 4 5
-5 -4 -3 -2 -1 0 1 2 3 4 5

This time im deleting columns. range (-3<A<3)

Is it possible to do that?

Thanks

  


Subject: Deleting cells

From: French Caro

Date: 17 Jun, 2008 14:35:02

Message: 8 of 9

"Ali Hussain" <hussaizj@aston.ac.uk> wrote in message
<g38hjm$ou7$1@fred.mathworks.com>...
> > > Hi,
> > >
> > > I have tried the above code and it worked only when I
> > > changed the dimension from 1 to 2(as in the code
> below).
> > > Is there a way that this can be changed so i can
> > > automatically specify the dimension as its used for a
> > > 1024x168 double matrix.
> > >
> > > >> idx=abs(max(Sheet1,[],2))>3;
> > > >> Sheet1(idx,:)=[]
> > >
> > > Thanks
> >
> > Yes I was not sure of the third argument.
> > What do you mean by "Is there a way that this can be
> changed
> > so i can automatically specify the dimension" ?
> >
> > In this formula the dimension is not used.
> > It will work for any N*M matrix.
> > The 2 in max(A,[],2) just indicates the dimension along
> > where max is done (not sure I'm very clear on this sorry)
> >
> > Caroline
>
> Hi,
>
> Thank you for the response...
>
> I am also trying to do the same for another matrix
>
> -5 -4 -3 -2 -1 0 1 2 3 4 5
> -1 -4 -3 -2 -1 0 1 2 3 4 5
> -5 -4 -3 -2 -1 0 1 2 3 4 5
> -1 -4 -3 -2 -1 0 1 2 3 4 5
> -5 -4 -3 -2 -1 0 1 2 3 4 5
>
> This time im deleting columns. range (-3<A<3)
>
> Is it possible to do that?
>
> Thanks
>
Of course it is just the transpose.
btw you should have done it by transposing your matrix twice
but it is not the more efficient way.

So this should work :
idx=abs(max(A,[],1))>3;
A(:,idx)=[]

Subject: Deleting cells

From: Ali Hussain

Date: 23 Jun, 2008 10:08:02

Message: 9 of 9

"French Caro " <caro95470@nospam.free.fr> wrote in message
<g38i2m$16b$1@fred.mathworks.com>...



Hi,

I have rotated the Matrix using the below code,

th=30*pi/180; %angle of rotation;
Rz=[cos(th) -sin(th) 0;sin(th) cos(th) 0;0 0 1];
P=[x(:) y(:) z1(:)]*Rz; %rotate each point on surface
x=reshape(P(:,1),size0);%transform surface vertices back
into matrix
y=reshape(P(:,2),size0);
z1=reshape(P(:,3),size0);


I am having problems with using the

idx=abs(max(A,[],1))>3;
A(:,idx)=[]

as it shapes the original matrix rather than the rotated
matrix. Is there any way I can cut the rotated matrix.

Thanks
 

Tags for this Thread

Add a New Tag:

Separated by commas
Ex.: root locus, bode

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.

rssFeed for this Thread

Public Submission Policy

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Disclaimer prior to use.

Contact us at files@mathworks.com