Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with Facebook Sign In with Google Sign In with OpenID


We have migrated to a new platform! Please note that you will need to reset your password to log in (your credentials are still in-tact though). Please contact if you have questions.
Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Reference "previous index"

javamarketjavamarket Posts: 2Member
Hello and thank you for possibly helping. I'm trying to teach myself MatLab ... and haven't been able to find the solution to what seems fairly straight forward. I want to calculate across variables (e.g. element wise multiplication) but want to be able to reference the "previous variable" in array [italic]x[/italic]

For example, 2 one-dimensional arrays:

a = 1, 2, 3, 4, 5, 6, 7, 8, 9
b = 1, -1, 1, -1, 1, -1, 1, -1, 1

I want to calculate two variables, c and d.

c = a .* b
c = 1, -2, 3, -4, 5, -6, 7, -8, 9

now my issue is for variable d I want to take each element in a and multiply it by the element in b, but one index earlier. The first element in d can't have an answer as there is no -1 index in b so that we'll assign a zero.

d = [0; ....]
calculated results should be
d = [0], [2*1], [3*-1], [4*1], etc ...

This is a simplified version of what I'm trying to accomplish of course. If I can add clarity please let me know and thanks again.

Sign In or Register to comment.