×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

matlab question

matlab question

matlab question

(OP)
I am a Matlab newbie, and have been going through a Matlab guide as well as the help menus for about a week now, but I can't figure out how to write my first real script.  I have a 1024x1 vector (actually I have a couple hundred of these), and I want to create a new vector wherein each element is a function of the preceding element and the corresponding element in the original vector.  Specifically:

New Vector Element (i) = 0.55*Orig Vector Element (i-1) + 0.45*New Vector Element (i-1)

I know I need a 'for' loop, but I guess the thing I'm stuck on is how to tell Matlab to use the preceding value in the vector being populated. Help?  

RE: matlab question

You need to use an array.  Try this simple example.  Type the following lines into the matlab terminal and see the result.

a = [1,2,3,4,5]
a(1)
a(2)
n = 4;
a(n)
a(n-1)

As you should notice, you defined an array called a and referenced the array elements by the index and that the index can be another variable or an expression.

You are correct, that you can use a for loop to index i over a range.  For example:

for i = 2:5;
b(i) = a(i) + 0.5*a(i-1)
endfor

This creates a new array b = (1 + .5z^-1)*a



 

RE: matlab question

Newvector=Origvector*0;

for i=2:length(Newvector)
Newvector(i)=.45*Newvector(i-1)+.55*Origvector(i-1);
end

Might need to transpose origvector beforehand. also note i=1 problem.

 

Cheers

Greg Locock

SIG:Please see FAQ731-376: Eng-Tips.com Forum Policies for tips on how to make the best use of Eng-Tips.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources