Array index invalid
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
Array index invalid
Hello,
I am to calculate lateral stress but am unable to track why my array index is invalid. can you please help to solve my issue
Many thanks
Solved! Go to Solution.
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
The vector "value" you create in the program does not get a value in each turn of the for loop.
I inserted a "try and catch" at the position where the error is thrown
and it can be seen by the result
that "value" has just 14 elements when i=25 and so you obviously can't access element #24.
You have to check your nested series of "if ... else if .... if ... else ... etc." to assure that "value" is assigned a value in every 'round' of the for-loop.
BTW, your "index" function could be written by simply using the "match" function. Only difference is the behaviour if the value (z) is not found in the vector.
Your function returns 0 in this case but "match" will return an error. If this is mandatory you may throw in a try and catch as shown:
You may also do without this index function if you replace calls like
by
but you would have to assure that this if-statement is not called for the last i because then there is no element # i+1
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
The vector "value" you create in the program does not get a value in each turn of the for loop.
I inserted a "try and catch" at the position where the error is thrown
and it can be seen by the result
that "value" has just 14 elements when i=25 and so you obviously can't access element #24.
You have to check your nested series of "if ... else if .... if ... else ... etc." to assure that "value" is assigned a value in every 'round' of the for-loop.
BTW, your "index" function could be written by simply using the "match" function. Only difference is the behaviour if the value (z) is not found in the vector.
Your function returns 0 in this case but "match" will return an error. If this is mandatory you may throw in a try and catch as shown:
You may also do without this index function if you replace calls like
by
but you would have to assure that this if-statement is not called for the last i because then there is no element # i+1
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
one more question @Werner_E . with out using the "match" function, how can I locate the index number of an array based off a given number. In my case , I would like to locate the index number from "H_end.layer_vec.total" where the "H1.Active" number is situated. I tried with the following but not working. The reason I am hesitant to use match is because if the given number does not lie within "H_end.layer_vec.total" then it gives an error number. I like my sheet to be more universal in terms of the given 4 layers
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
I am not sure what you would like to achieve.
What should be returned if the parameter z is not a value within the vector H.end.layer_vec.total.
The same applies to using "match" with the "try" bracket around.
In case you would rather like to return the index of nearest value you may try the optional argument "near".!?
The reason your version does not seem to work is because of numeric precison / numeric round off error due to conversion m <-> ft
You can cope with that by not asking for exact equality but rather by asking if the difference is approximately zero.
Match seems to work OK, but you can use "near" to be on the safe side
You can see the numeric round-off error by evaluating the difference
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
