How can I efficiently pass variables from an m-file to a function in MATLAB?

  • Thread starter Thread starter andrew.c
  • Start date Start date
  • Tags Tags
    Matlab Variables
andrew.c
Messages
46
Reaction score
0
Hiya,

I have been trying for hours to figure out how to pass a variable from an m-file to a function,

i could get it to work by making the variables global, but I've beeen told this is inefficient.

Any ideas?
Cheers!
 
Physics news on Phys.org
Take a look at this Matlab tutorial, especially section 4-22. http://www.mathworks.com/access/helpdesk/help/pdf_doc/matlab/getstart.pdf
 
Perhaps I am misunderstanding the question, but you call the function in your main ".m" file (script).
Assuming your function name is "shift(input1, input2)", then it should be stored in "shift.m", (as it is a function, and they are typically stored in separate files). You call it appropriately with the correct function syntax. Remember in Matlab, you are passing copies of the variables into the function, like you would in C.
 

Similar threads

  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 11 ·
Replies
11
Views
3K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 5 ·
Replies
5
Views
4K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 5 ·
Replies
5
Views
3K
Replies
3
Views
4K
  • · Replies 1 ·
Replies
1
Views
2K