While loop for testing the end of vector (Matlab)
12 views (last 30 days)
If we have a long vector that we don't know its length, and we want use while loop to repeat the task than stop and exit from the loop when the vector length is at its end.
For example, if the vector length is 10000 bits so we repeat the calculation (of any task) until 10000 than we stop and exit.
But in my case, I don't know the length of my vector. So how can I program this please?
More Answers (1)
Daniel Pollard on 17 Feb 2021
Edited: Daniel Pollard on 17 Feb 2021
If you know that it's 1-dimensional, you can use
which returns the length of your vector. Also useful to know is
which returns the size of a matrix (eg, [2 2] for a 2x2 matrix, [10 1] for a 10x1 vector, etc).
Edit I've replaced length with numel - thank you Rik.