the meaning of length in my loop
2 views (last 30 days)
Show older comments
hii so my lecturer provide us with a code, and he wants us to understand the meaning of each line sadly i couldnt understand what does the length(n) means like why is it equal to 1?
% Function have 4 inputs i.e., n, p1, p2, and p2
% Where n can be a number or row vector function y=padovan(n, p1, p2, p3)
P(1)=p1; P(2)=p2; P(3)=p3;
% Check if n is vector or not
if length(n) == 1
for i=4:n P(i)=P(i-2)+P(i-3);
end
else for i=4:length(n) P(i)=P(i-2)+P(i-3);
end
end
y=P(n);
0 Comments
Answers (2)
Star Strider
on 23 Dec 2020
The line:
if length(n) == 1
It is not setting it equal to 1, it is testing logically if it is equal to 1.
Since this appears to be a homework assignment, I will let you explore the documentation in order to understand how the rest of the code works.
0 Comments
Cris LaPierre
on 23 Dec 2020
Every function in MATLAB is documented. There, you can find a description, examples, and more. Check out the documentation for length here.
0 Comments
See Also
Categories
Find more on Software Development Tools 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!