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:
trimming vector without rewriting it

Subject: trimming vector without rewriting it

From: ross

Date: 18 May, 2007 23:55:41

Message: 1 of 3

Is there a way to trim a few values off the end of a vector without implicitly
rewriting the vector?

Let's say we just want to trim the last value off the large vector A.
By watching a process monitor, I find that both
A = A(1:end-1);
and
A(end) = [];

operate by creating a modified copy of A. The problem is: this restricts the
max size of A to half of available memory, which is sometimes a significant
restriction. In theory, truncating a vector shouldn't require a copy
operation. Can it be done in Matlab without descending to mex or assembly?

Thanks
Ross

Subject: trimming vector without rewriting it

From: chmical

Date: 18 May, 2007 12:26:07

Message: 2 of 3

Any reason that you cannot use

A(size(A,1),:) = [];

erases the last row in a vector.
>
>
> Is there a way to trim a few values off the end of a vector without
> implicitly
> rewriting the vector?
>
> Let's say we just want to trim the last value off the large vector
> A.
> By watching a process monitor, I find that both
> A = A(1:end-1);
> and
> A(end) = [];
>
> operate by creating a modified copy of A. The problem is: this
> restricts the
> max size of A to half of available memory, which is sometimes a
> significant
> restriction. In theory, truncating a vector shouldn't require a
> copy
> operation. Can it be done in Matlab without descending to mex or
> assembly?
>
> Thanks
> Ross
>
>

Subject: trimming vector without rewriting it

From: Loren Shure

Date: 18 May, 2007 12:30:26

Message: 3 of 3

In article <464dcc7d$1@news.eftel.com.au>, ross@nospam.com says...
> Is there a way to trim a few values off the end of a vector without implicitly
> rewriting the vector?
>
> Let's say we just want to trim the last value off the large vector A.
> By watching a process monitor, I find that both
> A = A(1:end-1);
> and
> A(end) = [];
>
> operate by creating a modified copy of A. The problem is: this restricts the
> max size of A to half of available memory, which is sometimes a significant
> restriction. In theory, truncating a vector shouldn't require a copy
> operation. Can it be done in Matlab without descending to mex or assembly?
>
> Thanks
> Ross
>
>

no way I can think of...

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

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