Passing variables in MATLAB

  • Thread starter andrew.c
  • Start date
  • #1
46
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!
 

Answers and Replies

  • #3
8
0
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.
 

Related Threads on Passing variables in MATLAB

  • Last Post
Replies
9
Views
2K
  • Last Post
Replies
1
Views
3K
  • Last Post
Replies
9
Views
7K
  • Last Post
Replies
2
Views
2K
  • Last Post
Replies
2
Views
2K
  • Last Post
Replies
7
Views
15K
Replies
4
Views
8K
Replies
1
Views
2K
Top