1. Limited time only! Sign up for a free 30min personal tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Homework Help: Passing variables in MATLAB

  1. Feb 4, 2010 #1
    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!
     
  2. jcsd
  3. Feb 4, 2010 #2

    Mark44

    Staff: Mentor

  4. Feb 4, 2010 #3
    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.
     
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook