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 10:13:33

Message: 1 of 2

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,1000000);


vector1 = cumsum(feed1);

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,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: Sprinceana

Date: 19 Jul, 2009 09:09:02

Message: 2 of 2

>>help size

>>size(vector1)

>>size(vector2)


You can modify the size of your vector.


for i=start: step: final


Example:

vector1=[1 2 5]
for i=1:1:3
%define vector above
end

You vector has 3 elements.


or doing directly:

>>vector1=1:1:3

Defines the elements automatically: 1 2 and 3 (elements are comprised between 1 and 3 with the step 1)


>>vector2=1:2: 5

Defines the elements automatically 1 3 and 5 (elements are comprised between 1 and 5 with the step of 2)

And if you do:

>>size(vector1)
>>size(vector2)

You'll notice that they have the same size.

Hope this basic idea helps you!

Best regards,

Michael

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