Set value to an array element if the index exceeds the number of array elements
Show older comments
Im trying to set the value of an array element to zero if it exceeds the index.
For example let's suppose given the array: A = [1 2 3 4 5]. It has 5 elements. So when I enter A(5), it outputs "5". And when I enter A(6) it outputs an error, which is logic.
My objective is to make a general equation where I calculate with the elements of an array (where the size of the input array is variable) and if some element exceeds the array index, set it to a value (in my case to zero) and continue calculating.
Any suggestion on how to achieve this as simple as possible?
Thanks in advance
Accepted Answer
More Answers (0)
Categories
Find more on Matrix Indexing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!