Community Tip - When posting, your subject should be specific and summarize your question. Here are some additional tips on asking a great question. X
I have imported excel data and made column vectors from data. When I try to multiply elements with an index beginning somewhere in the range I get this.
Why do I get zero values and how might I eliminate this behavior?
Any help would be greatly appreciated.
Solved! Go to Solution.
By default vector indices start with number 0 and if you assign the vector element 5 a value, you are actually creating a 6-element vector. Elements #0 to 4 are set to 0.
So you might use index i-5 instead of i on the left hand side when you assign the multiplication result.
Other solutions like the usage of the "submatrix" function or the "trim" function are possible, too.
Furthermore you should move the return of the result from inside the loop to after the loop - it works the way you did, but its not good programming habit.
For future question you should consider attaching your worksheet and stating, which version of Prime you are using.
By default vector indices start with number 0 and if you assign the vector element 5 a value, you are actually creating a 6-element vector. Elements #0 to 4 are set to 0.
So you might use index i-5 instead of i on the left hand side when you assign the multiplication result.
Other solutions like the usage of the "submatrix" function or the "trim" function are possible, too.
Furthermore you should move the return of the result from inside the loop to after the loop - it works the way you did, but its not good programming habit.
For future question you should consider attaching your worksheet and stating, which version of Prime you are using.
You could also change the index starting value, it is controlled by the built-in constant ORIGIN:
But you probably shouldn't...
Success!
Luc
@LucMeekes wrote:
You could also change the index starting value, it is controlled by the built-in constant ORIGIN:
If he does so, he would multiply the wrong values! He would have to use index i+5 instead of i twice on the right hand side of the assignment!
So I sure would vote against changing ORIGIN to 5 😉
A better option may be to trim off the first five entries in the "Row" and "Center" vectors right ahead and then use a vectorized multiplication of the two. But without seeing the sheet and knowing the reason why the first five values in the vectors should not be used, we can't say for sure if that really is the better approach.