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:
Help with logic. Making two vectors equal in length.

Subject: Help with logic. Making two vectors equal in length.

From: Adshak

Date: 18 Jul, 2009 11:15:10

Message: 1 of 4

Dear All,
I have three vectors vector1 and vector 2 and finalvector2, such
that:

% Generating vector 1 %%%%

mu1 = 9.5;
sd1 = 0.645;

feed1 = normrnd(mu1,sd1,1,1000000);

vector1 = cumsum(feed1);

%cutoff
cutoff = max(vector1);


% Generating vector 2%%%%%

mu2 = 19.7; %mu2 needs to be larger than mu1. It cannot be
same or close to the value of mu1
sd2 = 0.645;

feed2 = normrnd(mu2,sd2,1,1000000); %length of samples here is
1000000

vector2 = cumsum(feed2);

%final vector2

finalvector2 = vector2 (vector2 < cutoff);

end


Now it is obvious, that the number of elements in finalvector2 is
going to be lot less than vector1, after application of 'cutoff'.
Ofcourse vector2 and vector 1 will be same in size. But what I want
is, even after the cutoff application, I want the number of elements
in finalvector2 to be more or less same as the number of elements in
vector1.


It is clear that I need to generate more elements in feed2 to achieve
this. The query is 'by how much?'

I would have guessed it would be a relation between the following
'cutoff' and 'No of elements I require' and 'Number of extra elements
in feed to generate'

I am doing something wrong in calculating this relationship and
implementing it though....

Can somebody please help me?

Will be very grateful for your responses.

Cheers,
Adshak.

Subject: Help with logic. Making two vectors equal in length.

From: Adshak

Date: 19 Jul, 2009 00:54:34

Message: 2 of 4

On Jul 18, 12:15 pm, Adshak <adshaikh.hip...@googlemail.com> wrote:
> Dear All,
> I have three vectors vector1 and vector 2 and finalvector2, such
> that:
>
> % Generating vector 1 %%%%
>
> mu1 = 9.5;
> sd1 = 0.645;
>
> feed1 = normrnd(mu1,sd1,1,1000000);
>
> vector1 = cumsum(feed1);
>
> %cutoff
> cutoff = max(vector1);
>
> % Generating vector 2%%%%%
>
> mu2 = 19.7;           %mu2 needs to be larger than mu1. It cannot be
> same or close to the value of mu1
> sd2 = 0.645;
>
> feed2 = normrnd(mu2,sd2,1,1000000); %length of samples here is
> 1000000
>
> vector2 = cumsum(feed2);
>
> %final vector2
>
> finalvector2 = vector2 (vector2 < cutoff);
>
> end
>
> Now it is obvious, that the number of elements in finalvector2 is
> going to be lot less than vector1, after application of 'cutoff'.
> Ofcourse vector2 and vector 1 will be same in size. But what I want
> is, even after the cutoff application, I want the number of elements
> in finalvector2 to be more or less same as the number of elements in
> vector1.
>
> It is clear that I need to generate more elements in feed2 to achieve
> this. The query is 'by how much?'
>
> I would have guessed it would be a relation between the following
> 'cutoff' and 'No of elements I require' and 'Number of extra elements
> in feed to generate'
>
> I am doing something wrong in calculating this relationship and
> implementing it though....
>
> Can somebody please help me?
>
> Will be very grateful for your responses.
>
> Cheers,
> Adshak.

Dear ALL,

To further clarify my query, how can I generate 1 million samples of
feed2 = (mu2,sd2,1,1000000) with the condition max(vector2)<= max
(vector1) being satisfied.

I will be very grateful for any response that can help me.

sincere thanks in advance.

Subject: Help with logic. Making two vectors equal in length.

From: ImageAnalyst

Date: 19 Jul, 2009 01:38:00

Message: 3 of 4

But you haven't said what values you want the "extra" elements to
take. In this example, I set them either to zero or cutoff. See if
this is what you're looking for:

clc;
close all;
workspace;
% Generate values from a normal distribution with specified mean and
standard deviation.
mu1 = 9.5;
sd1 = 0.645;
feed1 = mu1 + sd1 * randn(100, 1);
vector1 = cumsum(feed1);
%cutoff
cutoff = max(vector1);
% Generating vector 2%%%%%
mu2 = 19.7; %mu2 needs to be larger than mu1. It cannot be
same or close to the value of mu1
sd2 = 0.645;
feed2 = mu2 + sd2 * randn(100, 1);
vector2 = cumsum(feed2);
%final vector2
subplot(2,2,1);
plot(feed1, 'r');
hold on;
plot(feed2, 'g');
subplot(2,2,2);
plot(vector1, 'r');
hold on;
plot(vector2, 'g');
finalvector2a = cutoff * ones(length(vector2), 1);
finalvector2a(vector2 < cutoff) = vector2(vector2 < cutoff);
subplot(2,2,3);
plot(finalvector2a, 'b');
finalvector2b = cutoff * zeros(length(vector2), 1);
finalvector2b(vector2 < cutoff) = vector2(vector2 < cutoff);
subplot(2,2,4);
plot(finalvector2b, 'b');

Subject: Help with logic. Making two vectors equal in length.

From: Bruno Luong

Date: 19 Jul, 2009 06:04:01

Message: 4 of 4

Adshak <adshaikh.hipnet@googlemail.com> wrote in message <730987aa-f3c1-45d6-a612-d8e4b3877332@18g2000yqa.googlegroups.com>...
>
> To further clarify my query, how can I generate 1 million samples of
> feed2 = (mu2,sd2,1,1000000) with the condition max(vector2)<= max
> (vector1) being satisfied.
>
> I will be very grateful for any response that can help me.
>

This does what you want:

http://www.mathworks.com/matlabcentral/fileexchange/23832

Bruno

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