Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

MATLAB function

  1. Apr 19, 2010 #1
    Hi, i need to pass a function in matlab a few parameters, one of the parameters is an equation such as :
    and have it make the 3d graph, i have no problem setting up the meshgrid etc and getting it to work running strait from the m-file

    function graph = graph(f)
    x = (-n:1:n);
    y = (-n:1:n);
    [x,y] = meshgrid(x,y);




    example of running the function


    right now when i run it i get.

    ??? Error using ==> surf at 78
    Z must be a matrix, not a scalar or vector.

    Error in ==> graph at 7

    Any advice would be great.
  2. jcsd
  3. Apr 19, 2010 #2
    Look up "help function pointer" and follow their examples.
  4. Apr 20, 2010 #3
    Two things,

    1) Change the line z = f to z = f(x,y)

    2) When you call the function, use graph(@(x,y) cos(x) - sin(y))
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook