How do I enter a user-defined function in MATLAB? This needs to be a way for the
ID: 3812863 • Letter: H
Question
How do I enter a user-defined function in MATLAB? This needs to be a way for the user to enter a file's data to solve the problem, not just me telling MATLAB which file to open or entering the data.
Make the following changes to your previous MATLAB fan or pump selection program. recommend you copy your Homework 6 program to a new file name, and make the changes to the new file. That way you will still have your working Homework 6 program to refer to as you work on completing your Homework 7 program. Revise the comment section in your Homework 7 program as necessary. The two new components for this version of the program are: 1) get the fan or pump curve data from a file rather than having the user type it in, and 2) create a user-defined function that uses the fan or pump curve data and performs the second-order least-squares curve fit calculations.Explanation / Answer
You can have user defined functions in MATLAB.
Steps:
1) Write the function in a file and save the file with the same name as function name.
2) Save this file either in the current folder or in a folder on the MATLAB search path.
3) You may call the function from the command line, using the same syntax rules that apply to default MATLAB functions.
eg: Let's make a function fact.m to calculate factorial of a number and save in a file named fact.m in the current folder.
fact.m file has the following code:
Save this file named fact.m
Now using the CLI, write the following:
a=5;
b=fact(a)
output:
b=120
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.