Got Questions? Get Answers.
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:
Deleting stored row, column and page subscripts

Subject: Deleting stored row, column and page subscripts

From: Lin

Date: 9 Feb, 2009 14:50:02

Message: 1 of 5

The ind2sub function is used to store the row, column and page subscript shown as below:

I J K
1 2 1 % Row 1
2 2 1
3 3 2
5 3 2
4 5 1 % Row 5
3 5 1 % Row 6

Now i want to delete those items which i do not need them. For example, i dont need J=3, therefore i remove row 3 and 4.

After which, the row, column and page subscripts of row 5 and 6 will fill up the empty slots.

Expected results:

I J K
1 2 1 % Row 1
2 2 1
4 5 1 % Row 3
3 5 1 % Row 4

Thank you for any suggestions and recommendations.

Subject: Deleting stored row, column and page subscripts

From: Loren Shure

Date: 9 Feb, 2009 15:31:00

Message: 2 of 5

In article <gmpfqq$ohe$1@fred.mathworks.com>, shenqlv@yahoo.com says...
> The ind2sub function is used to store the row, column and page subscript shown as below:
>
> I J K
> 1 2 1 % Row 1
> 2 2 1
> 3 3 2
> 5 3 2
> 4 5 1 % Row 5
> 3 5 1 % Row 6
>
> Now i want to delete those items which i do not need them. For example, i dont need J=3, therefore i remove row 3 and 4.
>
> After which, the row, column and page subscripts of row 5 and 6 will fill up the empty slots.
>
> Expected results:
>
> I J K
> 1 2 1 % Row 1
> 2 2 1
> 4 5 1 % Row 3
> 3 5 1 % Row 4
>
> Thank you for any suggestions and recommendations.
>

Maybe this will help:

X = [1 2 1
2 2 1
3 3 2
5 3 2
4 5 1
3 5 1 ]

rows = find(X(:,2)==3);
X(rows) = [];


--
Loren
http://blogs.mathworks.com/loren

Subject: Deleting stored row, column and page subscripts

From: us

Date: 9 Feb, 2009 15:44:02

Message: 3 of 5

Loren Shure
> X = [1 2 1
> 2 2 1
> 3 3 2
> 5 3 2
> 4 5 1
> 3 5 1 ]
> rows = find(X(:,2)==3);
> X(rows) = [];

must read:

     X(rows,:)=[];

us

Subject: Deleting stored row, column and page subscripts

From: Lin

Date: 10 Feb, 2009 12:01:02

Message: 4 of 5

"us " <us@neurol.unizh.ch> wrote in message <gmpj02$qid$1@fred.mathworks.com>...
> Loren Shure
> > X = [1 2 1
> > 2 2 1
> > 3 3 2
> > 5 3 2
> > 4 5 1
> > 3 5 1 ]
> > rows = find(X(:,2)==3);
> > X(rows) = [];
>
> must read:
>
> X(rows,:)=[];
>
> us

Thanks.

If we need to delete different rows (you may refer to case 1 and 2), will the code still be valid? Is there a more generic code for that? Please kindly advise. thanks.

Case 1:
%Initial Value
X = [
1 2 1
2 2 1
3 4 2
5 4 2
4 5 1
3 5 1 ]

%Expected result
X = [
3 4 2
5 4 2 ]

Case 2:

%Initial Value
X = [
1 1 1
2 2 1
3 3 2
5 4 2
4 5 1
3 6 1 ]

%Expected result
X = [
2 2 1
5 4 2
3 6 1]

Subject: Deleting stored row, column and page subscripts

From: us

Date: 10 Feb, 2009 15:32:01

Message: 5 of 5

"Lin"
> If we need to delete different rows (you may refer to case 1 and 2), will the code still be valid? Is there a more generic code for that? Please kindly advise. thanks.
> %Initial Value
> X = [
> 1 2 1
> 2 2 1
> 3 4 2
> 5 4 2
> 4 5 1
> 3 5 1 ]
> %Expected result
> X = [
> 3 4 2
> 5 4 2 ]

one of the solutions

% the data
     n=[2,5]; % <- remove all rows with col#2 values 2|5
     m=[
          1 2 1
          2 2 1
          3 4 2
          5 4 2
          4 5 1
          3 5 1
     ];
% the engine
     rx=ismember(m(:,2),n);
     m(rx,:)=[];
% the result
     disp(m);
%{
          3 4 2
          5 4 2
%}

us

Tags for 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