Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

mukushla

  • 3 years ago

how to write and call a simple function in matlab?

  • This Question is Closed
  1. ADGENIUS
    • 3 years ago
    Best Response
    You've already chosen the best response.
    Medals 1

    Syntex: function [y1,...,yN] = myfun(x1,...,xM)example Description: function [y1,...,yN] = myfun(x1,...,xM) declares a function named myfun that accepts inputs x1,...,xM and returns outputs y1,...,yN. This declaration statement must be the first executable line of the function. Save the function code in a text file with a .m extension. The name of the file should match the name of the first function in the file. Valid function names begin with an alphabetic character, and can contain letters, numbers, or underscores. Example: Define a function in a file named average.m that accepts an input vector, calculates the average of the values, and returns a single result. function y = average(x) if ~isvector(x) error('Input must be a vector') end y = sum(x)/length(x); Call the function from the command line. z = 1:99; average(z) ans = 50 for more detail visit: http://www.mathworks.com/help/matlab/ref/function.html#btexm3w

  2. mukushla
    • 3 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    thank u very much :)

  3. Not the answer you are looking for?
    Search for more explanations.

    • Attachments:

Ask your own question

Sign Up
Find more explanations on OpenStudy
Privacy Policy