Write a function in MATLAB

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello and welcome we are going to write a function that calculates x plus y multiplied by 10. the values of x and y are given as inputs to the function and the value of a which is the result is taken as output from the function let's start a new one file first of all we write function and between brackets the output variable which is a equals the name of the function we can choose any name let's say my function and between parentheses we write the input variables which are x and y now we write the equation a which is the output variable equals x plus y multiplied by 10. now we end the function by writing end note that the name of the function should not contain any space now let's save the function there are two nodes we should consider when we save a function the first is that the file name should be the same as the function name and the second is that the file should be saved in the current folder on the left of the screen for example if the current folder is my documents the file should be saved in my documents now let's save the file by clicking save now we see that the file is saved in the current folder now let's call the function first of all let's define the input variables x let's say 2 and y equals 3. now let's call the function the output variable which is a equals the name of the function my function and the input variables x comma y we see that the result is 50 which is 2 plus 3 equals 5 multiplied by 10. we can also call the function in this way by giving the values of x and y immediately we can also choose another variable let's say m equals my function also we see the same result we can add another input variable let's say that and also we can change the equation x plus y plus z and we save the changes now we can call the function let's define that set equals for as an example now we call the function a equals my function x y and that now the result is 90 because 2 plus 3 plus 4 equals 9 multiplied by 10 equals 90. we can also add another output variable let's say b and we can write another equation as well b equals x multiplied by y multiplied by z as an example now we save the changes now let's call the function now we have two output variables so we write between brackets a comma b which are the output variables equals my function two in brackets x comma y and comma z we see that a equals 90 and b equals 24 b equals x multiplied by y multiplied by that this means two multiplied by three multiplied by four equals twenty four thank you very much
Info
Channel: Engineer2009Ali
Views: 220,918
Rating: 4.865922 out of 5
Keywords:
Id: jjhmU6iJ1aU
Channel Id: undefined
Length: 4min 28sec (268 seconds)
Published: Thu Jul 25 2013
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.