00:02
Suppose the following function is called with the medlap comments b equals 5, c equals the array 2, 3, and x out equal b photo, you call the function, with arguments b and c.
00:20
What will be the value of x out in the base workspace after the function executes? and here we have the function, v -foddle.
00:33
It has, in its definition, two arguments, a and varan.
00:38
Barakin is a variable number of arguments following the second argument.
00:47
And here we are calling the function with variable b, which is a number, b equal 5.
00:54
And c is a matrix of one row and two columns.
00:59
It's in fact a row vector, but from madlab, that's a matrix.
01:08
And then we call the function b -foddle with first argument the number b containing the variable b, number 5, and then the array 2 -3 containing variable c.
01:22
The result of the call of the function v -foto with these two arguments is the result is save in the variable x -out and that's a variable we want to know the value after the call of the function if there is a value that the function get out and here we have the definition so we have the bar argument expecting any number of arguments after the second argument and then this is the body of the function and here there is something i get to say very important in order to understand the function is given there is an space here else if there is an space here we know that the else if common in madlab is a single word not two words and for that reason this space here after the else in this line is really interpreted as this for the software because the if coming after this elf is another comment it's not an else if common so matlav expect an if then it finds here an else corresponding to that if here and then he finds an n which he tied to the if the inner if is this comment here.
03:02
After the n, the first n is found and bind to this if here, then there's another n, which is bound to the if that we have up here.
03:19
So this is the structure, the real structure of the program, as it is written.
03:24
That is, the key thing to know that is that the, there is certain space here.
03:36
So it's not an else if common but an else common followed by an inner if which is this one here.
03:46
Anyway we can follow along the the execution as a program and another thing we got to say is there is no end needed for the function common in matlap.
04:03
So there is no problem when he found this is self -n structure and then this other if else n structure the function is complete that is it doesn't need an end to close a function is optional you get to put that when you have more functions in the same file but when you have one the end to close a function is not necessary okay so having said that now we're going to see what happens when we execute the function over here.
04:39
So the first variable is copied into the first argument in the definition of the function.
04:48
So this variable a will have the value 5.
04:52
N is a value copy.
04:53
That is there is not, it's not the same variable in memory, but a copy of that.
04:58
And this c will be saved in the bar argument.
05:05
Remember, a bargain argument is a cell array.
05:09
It's a cell array.
05:11
That is, it will contain all the variables that comes from the second one, in this case, up to the end.
05:19
That is, we can have more arguments in this function here.
05:23
And all the arguments after the first one that is starting at the second argument up to the last argument will be guard or save in the bar -argin cell array.
05:35
And each entry of the cell array will be each of the success.
05:42
Arguments after the first one.
05:45
In this case, there is only one, that is c.
05:48
So the variegian cell array will have only one element, which is, in this case, c, which is, in fact, an array.
05:58
The thing to use the cell array is that the cell arrays can contain any type of elements of objects in mad lab.
06:09
And that's the reason why they use the array.
06:11
That is, you can pass here.
06:14
Strings, you can pass matrices, you can pass numbers, logical variables, you can pass anything, and that will be safe in the cell array without any problem.
06:28
Okay, so the vargin cell array contains only one element in this case, and that will be c, the content of c, that is the matrix 23, that is the matrix of one row and two columns.
06:48
So let's follow along the execution of the program.
06:55
So narkeen corresponds to the number of arguments that were given in the call of the function.
07:04
And that in this case is 2.
07:07
So narquin is not 3.
07:09
Here we are comparing with equality.
07:12
So the number of argument in entering the function is not 3.
07:18
So we go to the else statement...