Indexing means that you can assign the numerical feature to a variable in Matlab®. Indexing tools and commands in Matlab® is also very superior compared with other programming languages. Because of this reason, Matlab® is a very superior mathematical calculation programming language. Also, you can index the number of elements of a vector in Matlab® to a variable. You can do this kind of thing with the ‘length()’ command in Matlab®. In this article, we will show the use of the length() command in Matlab® with a very basic example below.
>> a = logspace(1,3,5) b = length(a) c = 3*length(a) d = b*c a = 1.0e+03 * 0.0100 0.0316 0.1000 0.3162 1.0000 b = 5 c = 15 d = 75 >>
For example, we have a vector called ‘a’, and the number of elements of this vector ‘a’ is ‘6’ as shown above. We created a variable called ‘b’ with length(a), which has a value of ‘6’ as shown above. So you see that the number of elements of ‘a’ is the value of ‘b’.
YOU CAN LEARN MatLab® IN MECHANICAL BASE; Click And Start To Learn MatLab®!
As you can see from the ‘c’ and ‘d’ variables, we can do various mathematical calculations with that length() function as shown above.
This length() code can be very useful in such calculations. For example, you have a vector that each element that represents the grade of a student in your class. When you add a grade to that vector the number of students in this class also increases. If you need a mathematical calculation with student numbers, you can use this lenght() command that will use the updated student number inside the vector.
The use of the length() command in Matlab® is very easy and useful like above. Do not forget to leave your comments and questions about the ‘length()’ command in Matlab® below!
This article is prepared for completely educative and informative purposes. Images used courtesy of Matlab®
Your precious feedbacks are very important to us.