Matlab m file function with multiple variables

In summary, the user is struggling with integrating a MATLAB function and setting values for variables a and b. They are having trouble using the quadgk command and have also encountered a separate issue with a timer in a GUI. They are seeking help and have provided an email address for further assistance.
  • #1
strokebow
123
0
Hi,

I have a MATLAB function m file and I want to integrate the function.

Code:
function y = myfun(t,a,b)

y = (1/(2*pi)).*(1./t)*(1i*(a+b));
end
Then when I call the integration in MATLAB I don't know how to specify a and b whilst integrating over t.

I need to be able to set a and b outside of the function m file and then call the integral.

R=quadgk(@myfun,0,Inf)
This command will not work. a and b need to be set. I want to set a and b (this can vary) and then run the integral. I have tried set a and b in the MATLAB workspace but that still doesn't work.

Please can anyone help?
** Also, please let me know if my explanation is not clear?

Thanks
 
Last edited:
Physics news on Phys.org
  • #2
Solved it.

Its how you call the function.

It should be:

R=quadgk(@(t)myfun(t,a,b),0,Inf)

simples.
 
  • #3
hi to all
I have a problem with timer in gui in matlab
i want to to show real time in gui figure but when run the timer mfile it create a new figure
seperatly from main figure

any one can help me?
if know a way for this problem please help me ...
my email address is : mhmz66@yahoo.com
tnx so mucho:)
 

1. What is an "m file function" in Matlab?

An m file function in Matlab is a user-defined function written in a file with a .m extension. It allows users to create custom functions with multiple input and output variables for repeated use in a program.

2. How do I create a Matlab m file function with multiple variables?

To create a Matlab m file function with multiple variables, you can follow these steps:

  • Open the Matlab editor and create a new file with a .m extension.
  • Define the function name, input variables, and output variables using the function keyword.
  • Write the code inside the function that performs the desired task.
  • Save the file and use the function in your program by calling its name and passing the required input variables.

3. Can I use a Matlab m file function with multiple variables in a loop?

Yes, you can use a Matlab m file function with multiple variables in a loop. You can define the function outside the loop and call it with different input variables inside the loop to perform the desired task repeatedly.

4. How do I handle errors in a Matlab m file function with multiple variables?

To handle errors in a Matlab m file function with multiple variables, you can use the try-catch block. The try block contains the code that may cause an error, and the catch block handles the error by displaying a message or performing a specific action.

5. What is the difference between input and output variables in a Matlab m file function with multiple variables?

Input variables are the variables that are passed to the function as arguments when it is called, and they are used to perform the desired task. Output variables are the variables that store the result or value returned by the function after it is executed. They are declared in the function definition and can be accessed outside the function after it is called.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
995
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
8
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
3
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
13
Views
2K
Back
Top