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 rows from matrices

Subject: deleting rows from matrices

From: Peter Smith

Date: 13 Aug, 2010 19:38:04

Message: 1 of 7

Hi all, i posted this message moments ago

i am looping through a number of matrices, they all contain a vector tmptime

I want to tell matlab to delete all rows of tmptime after row 800
The length of rows vary between matrices.

How can i tell matlab to just delete after 800 rows without specifying the final row.

Please could someone help i am very stuck

Someone kindly replied tmpTime(800:end)=[]
However, some matrices do not have 800 rows, whilst some have significantly more.
I get an error message due to some not having 800 rows.

Is it possible to tell matlab, something like, if they exist, delete after 800 rows?

Please could someone help?

Subject: deleting rows from matrices

From: Walter Roberson

Date: 13 Aug, 2010 19:41:54

Message: 2 of 7

Peter Smith wrote:

> Someone kindly replied tmpTime(800:end)=[]

I believe they used 801 not 800, as you wanted to delete the ones *after* 800.

> However, some matrices do not have 800 rows, whilst some have
> significantly more.
> I get an error message due to some not having 800 rows.
>
> Is it possible to tell matlab, something like, if they exist, delete
> after 800 rows?

tmpTime(min(800,end)+1:end) = [];

Subject: deleting rows from matrices

From: Matt J

Date: 13 Aug, 2010 19:45:06

Message: 3 of 7

"Peter Smith" <fe09ae@mail.wbs.ac.uk> wrote in message <i446us$k4q$1@fred.mathworks.com>...


> However, some matrices do not have 800 rows, whilst some have significantly more.
> I get an error message due to some not having 800 rows.
>
> Is it possible to tell matlab, something like, if they exist, delete after 800 rows?
======

if length(tmpTime)>=800,
 tmpTime=tmpTime(1:800);
end

Subject: deleting rows from matrices

From: Sean

Date: 13 Aug, 2010 19:46:07

Message: 4 of 7

"Peter Smith" <fe09ae@mail.wbs.ac.uk> wrote in message <i446us$k4q$1@fred.mathworks.com>...
> Hi all, i posted this message moments ago
>
> i am looping through a number of matrices, they all contain a vector tmptime
>
> I want to tell matlab to delete all rows of tmptime after row 800
> The length of rows vary between matrices.
>
> How can i tell matlab to just delete after 800 rows without specifying the final row.
>
> Please could someone help i am very stuck
>
> Someone kindly replied tmpTime(800:end)=[]
> However, some matrices do not have 800 rows, whilst some have significantly more.
> I get an error message due to some not having 800 rows.
>
> Is it possible to tell matlab, something like, if they exist, delete after 800 rows?
>
> Please could someone help?


if size(matrix,1) >=800 %size of the matrix first dimension (i.e. number of rows)
    delete...
end

Subject: deleting rows from matrices

From: Peter Smith

Date: 13 Aug, 2010 19:46:07

Message: 5 of 7

Walter i am very greatful.

Subject: deleting rows from matrices

From: Steven_Lord

Date: 13 Aug, 2010 20:41:24

Message: 6 of 7



"Matt J " <mattjacREMOVE@THISieee.spam> wrote in message
news:i447c2$ga4$1@fred.mathworks.com...
> "Peter Smith" <fe09ae@mail.wbs.ac.uk> wrote in message
> <i446us$k4q$1@fred.mathworks.com>...
>
>
>> However, some matrices do not have 800 rows, whilst some have
>> significantly more.
>> I get an error message due to some not having 800 rows.
>>
>> Is it possible to tell matlab, something like, if they exist, delete
>> after 800 rows?
> ======
>
> if length(tmpTime)>=800,
> tmpTime=tmpTime(1:800);
> end

Remember that LENGTH returns the largest size in any dimension (or 0 if the
matrix is empty), which may not be the number of rows. Instead call SIZE
with the appropriate dimension (for the number of rows, that would be
dimension 1) input.

--
Steve Lord
slord@mathworks.com
comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

Subject: deleting rows from matrices

From: Peter Smith

Date: 13 Aug, 2010 20:57:04

Message: 7 of 7

Thanks for all your helpful mesages

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