Thread Subject: split to 100 values

Subject: split to 100 values

From: Chris

Date: 17 Nov, 2009 03:09:02

Message: 1 of 6

This should be quite simple,

I have numerous vectors of varying length. I want them all to be 1x100 vectors so I can compare them. I did this years ago but have not used matlab for a while and cannot remember how. Your help is appreciated.

Subject: split to 100 values

From: Steven Lord

Date: 17 Nov, 2009 14:30:59

Message: 2 of 6


"Chris " <chris.barr@health.sa.gov.au> wrote in message
news:hdt44e$fe$1@fred.mathworks.com...
> This should be quite simple,
>
> I have numerous vectors of varying length. I want them all to be 1x100
> vectors so I can compare them. I did this years ago but have not used
> matlab for a while and cannot remember how. Your help is appreciated.

That depends.

If you just want to chop off the end of those signals that are longer than
100 elements:

x = x(1:100);
% or
x(101:end) = [];

If you want to pad those vectors that are shorter than 100 elements with NaN
values:

x = [x; NaN(100-numel(x), 1)] % Assuming x is a column vector
x(end+1:100) = NaN;

If you want to interpolate the values in your vector to obtain the value at
a vector of 100 uniformly-spaced times, look at INTERP1 or the DECIMATE
function from Signal Processing Toolbox.

If you have another method that you want to use to shrink/grow the vectors
to be 100 elements long, describe that method and someone here may be able
to help you implement it (or describe which function that already exists
implements it.)

--
Steve Lord
slord@mathworks.com
comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ

Subject: split to 100 values

From: Chris

Date: 17 Nov, 2009 23:52:02

Message: 3 of 6

"Steven Lord" <slord@mathworks.com> wrote in message <hduc11$t14$1@fred.mathworks.com>...
>
> "Chris " <chris.barr@health.sa.gov.au> wrote in message
> news:hdt44e$fe$1@fred.mathworks.com...
> > This should be quite simple,
> >
> > I have numerous vectors of varying length. I want them all to be 1x100
> > vectors so I can compare them. I did this years ago but have not used
> > matlab for a while and cannot remember how. Your help is appreciated.
>
> That depends.
>
> If you just want to chop off the end of those signals that are longer than
> 100 elements:
>
> x = x(1:100);
> % or
> x(101:end) = [];
>
> If you want to pad those vectors that are shorter than 100 elements with NaN
> values:
>
> x = [x; NaN(100-numel(x), 1)] % Assuming x is a column vector
> x(end+1:100) = NaN;
>
> If you want to interpolate the values in your vector to obtain the value at
> a vector of 100 uniformly-spaced times, look at INTERP1 or the DECIMATE
> function from Signal Processing Toolbox.
>
> If you have another method that you want to use to shrink/grow the vectors
> to be 100 elements long, describe that method and someone here may be able
> to help you implement it (or describe which function that already exists
> implements it.)
>
> --
> Steve Lord
> slord@mathworks.com
> comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ
>


Thanks Steven, I tried the interp1 command yesterday, and it didn't work. For some reason it is working fine today.

%A is vector of 3019 values
x=[1:100];
Ai = interp1(A,X);
%Ai is a vector of 100 values from A equally spaced.

Regards

Chris

Subject: split to 100 values

From: Chris

Date: 18 Nov, 2009 01:42:05

Message: 4 of 6

"Chris " <chris.barr@health.sa.gov.au> wrote in message <hdvcv2$1b$1@fred.mathworks.com>...
> "Steven Lord" <slord@mathworks.com> wrote in message <hduc11$t14$1@fred.mathworks.com>...
> >
> > "Chris " <chris.barr@health.sa.gov.au> wrote in message
> > news:hdt44e$fe$1@fred.mathworks.com...
> > > This should be quite simple,
> > >
> > > I have numerous vectors of varying length. I want them all to be 1x100
> > > vectors so I can compare them. I did this years ago but have not used
> > > matlab for a while and cannot remember how. Your help is appreciated.
> >
> > That depends.
> >
> > If you just want to chop off the end of those signals that are longer than
> > 100 elements:
> >
> > x = x(1:100);
> > % or
> > x(101:end) = [];
> >
> > If you want to pad those vectors that are shorter than 100 elements with NaN
> > values:
> >
> > x = [x; NaN(100-numel(x), 1)] % Assuming x is a column vector
> > x(end+1:100) = NaN;
> >
> > If you want to interpolate the values in your vector to obtain the value at
> > a vector of 100 uniformly-spaced times, look at INTERP1 or the DECIMATE
> > function from Signal Processing Toolbox.
> >
> > If you have another method that you want to use to shrink/grow the vectors
> > to be 100 elements long, describe that method and someone here may be able
> > to help you implement it (or describe which function that already exists
> > implements it.)
> >
> > --
> > Steve Lord
> > slord@mathworks.com
> > comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ
> >
>
>
> Thanks Steven, I tried the interp1 command yesterday, and it didn't work. For some reason it is working fine today.
>
> %A is vector of 3019 values
> x=[1:100];
> Ai = interp1(A,X);
> %Ai is a vector of 100 values from A equally spaced.
>
> Regards
>
> Chris


Sorry, this is not what I was after. This solution only gives the first 100 values of A.

what I have is vectors
A <1x3019>
B <1x2346>
C <1x4529>
etc etc
these are values (angles) taken over time taken to complete a task. I want to normalise these so that the full range of data is there, but so that all new vectors are <1x100>
For example, if I had values [1, 2, 3] and I wanted it to be a vector of length 5 instead of 3, the new values would be [1, 1.5, 2, 2.5, 3]

I hope that makes more sense.

Chris

Subject: split to 100 values

From: Darren Rowland

Date: 18 Nov, 2009 02:05:22

Message: 5 of 6


> Sorry, this is not what I was after. This solution only gives the first 100 values of A.
>
> what I have is vectors
> A <1x3019>
> B <1x2346>
> C <1x4529>
> etc etc
> these are values (angles) taken over time taken to complete a task. I want to normalise these so that the full range of data is there, but so that all new vectors are <1x100>

Chris,

Is it the case that you want to take 100 evenly spaced samples from the vectors?
This may do the job

x = 1:100;
k = 240;
A = rand(1,k);
A100 = A(round(x*k/100));

Hth
Darren

Subject: split to 100 values

From: Chris

Date: 19 Nov, 2009 02:56:19

Message: 6 of 6

"Darren Rowland" <darrenjremovethisrowland@hotmail.com> wrote in message <hdvkp2$nme$1@fred.mathworks.com>...
>
> > Sorry, this is not what I was after. This solution only gives the first 100 values of A.
> >
> > what I have is vectors
> > A <1x3019>
> > B <1x2346>
> > C <1x4529>
> > etc etc
> > these are values (angles) taken over time taken to complete a task. I want to normalise these so that the full range of data is there, but so that all new vectors are <1x100>
>
> Chris,
>
> Is it the case that you want to take 100 evenly spaced samples from the vectors?
> This may do the job
>
> x = 1:100;
> k = 240;
> A = rand(1,k);
> A100 = A(round(x*k/100));
>
> Hth
> Darren

Thanks Darren,

by putting A=(angle_vector)
and k=length(A)

it works a treat!

Tags for this Thread

Everyone's Tags:

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.

Tag Activity for This Thread
Tag Applied By Date/Time
split Sprinceana 17 Nov, 2009 10:24:34
rssFeed for this Thread

Contact us at files@mathworks.com