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:
Reduce the size of a vector

Subject: Reduce the size of a vector

From: Alex

Date: 9 Jan, 2012 11:30:10

Message: 1 of 6

Dear all I have a data vector of 1601 elements and I want to reduce its size to 101, to be able to compare it with a vector of 101 elements.

IS there in matlab any function that can reduce the 1601 elements to 101? The easier would be to take concecutive elements of the 1601 vector and find the mean value in such steps so to end to a 101 vector.

Do you know if there is a function that can do that?

B.R
Alex

Subject: Reduce the size of a vector

From: someone

Date: 9 Jan, 2012 19:18:08

Message: 2 of 6

"Alex " <alaios@yahoo.com> wrote in message <jeej42$m37$1@newscl01ah.mathworks.com>...
> Dear all I have a data vector of 1601 elements and I want to reduce its size to 101, to be able to compare it with a vector of 101 elements.
>
> IS there in matlab any function that can reduce the 1601 elements to 101? The easier would be to take concecutive elements of the 1601 vector and find the mean value in such steps so to end to a 101 vector.
>
> Do you know if there is a function that can do that?
>
> B.R
> Alex

I don't have MATLAB installed on this computer,
but you should be able to use FILTER to take a
running average of your vector (in blocks of 16 say).
Then use only every 16th eleemnet of this vector.
Something like:

data = % your 1601 data vetctor
windowSize = 16;
x = filter(ones(1,windowSize)/windowSize,1,data);
y = x(1:16 :end)

You will have to play around with the last
statement to make y a 101 length vector.

Subject: Reduce the size of a vector

From: ScottB

Date: 9 Jan, 2012 20:29:08

Message: 3 of 6

"Alex " <alaios@yahoo.com> wrote in message <jeej42$m37$1@newscl01ah.mathworks.com>...
> Dear all I have a data vector of 1601 elements and I want to reduce its size to 101, to be able to compare it with a vector of 101 elements.
>
> IS there in matlab any function that can reduce the 1601 elements to 101? The easier would be to take concecutive elements of the 1601 vector and find the mean value in such steps so to end to a 101 vector.
>
> Do you know if there is a function that can do that?
>
> B.R
> Alex

Alex,
The interp function can do that nicely.

ScottB

Subject: Reduce the size of a vector

From: Matt J

Date: 9 Jan, 2012 21:39:08

Message: 4 of 6

"Alex " <alaios@yahoo.com> wrote in message <jeej42$m37$1@newscl01ah.mathworks.com>...
>
> The easier would be to take concecutive elements of the 1601 vector and find the mean value in such steps so to end to a 101 vector.
=================

Since 1601 is a prime number, it is not clear how you would divide it into subgroups for the purposes of taking the mean value.


>> isprime(1601)

ans =

     1

Subject: Reduce the size of a vector

From: Alex

Date: 10 Jan, 2012 10:46:09

Message: 5 of 6

Did it with interp , even though interp can average the concecutive bins to one.

Subject: Reduce the size of a vector

From: ivandimit@gmail.com

Date: 5 Mar, 2013 21:18:11

Message: 6 of 6

On Tuesday, January 10, 2012 3:46:09 AM UTC-7, Alex wrote:
> Did it with interp , even though interp can average the concecutive bins to one.

Could you elaborate how you did this? I am still learning how to use Matlab (coming from perl, so it's a big switch) and have a similar problem to what you had (many arrays of numbers that I would like to re-size to the same length, without loosing too much data).

Thanks

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