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:
Need help creating vector based on sections of another (larger) vector

Subject: Need help creating vector based on sections of another (larger) vector

From: cristian254

Date: 2 Apr, 2013 17:29:06

Message: 1 of 2

I created something like this:

% This would be the first iteration
x1 = MainVectorX(1:maxindex);
y1 = MainVectorY(1:maxindex);
z1 = nanmean(x1 .* y1);

MainVectorX being a vector with some NaN values
MainVectorY being a vector with "double" type values
maxindex is a number < length(MainVectorX) & < length(MainVectorY)

Now, what I would like to do is create a vector with all the possible values of z while moving the averaging window of size maxindex (i.e. values of z from 1+1 to maxindex+1, from 1+2 to maxindex+2, etc.)

At the end I would like to have all possible values of z in one vector. Any suggestions?

Subject: Need help creating vector based on sections of another (larger) vector

From: Josh Meyer

Date: 2 Apr, 2013 20:06:30

Message: 2 of 2

Not totally sure this will work for you depending on the specifics, but it's
a good start:

z = zeros(1,length(MainVectorX)-maxindex+1);
for i=1:length(MainVectorX)-maxindex+1
     M = maxindex+i;
    x1 = MainVectorX(i:M-1);
    y1 = MainVectorY(i:M-1);
    z(i) = nanmean(x1 .* y1);
end

"cristian254 " <cristian254@gmail.com> wrote in message
news:kjf4h2$5ag$1@newscl01ah.mathworks.com...
> I created something like this:
>
> % This would be the first iteration
> x1 = MainVectorX(1:maxindex);
> y1 = MainVectorY(1:maxindex);
> z1 = nanmean(x1 .* y1);
>
> MainVectorX being a vector with some NaN values
> MainVectorY being a vector with "double" type values
> maxindex is a number < length(MainVectorX) & < length(MainVectorY)
>
> Now, what I would like to do is create a vector with all the possible
> values of z while moving the averaging window of size maxindex (i.e.
> values of z from 1+1 to maxindex+1, from 1+2 to maxindex+2, etc.)
>
> At the end I would like to have all possible values of z in one vector.
> Any suggestions?

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