Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7169151
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T14:55:41+00:00 2026-05-28T14:55:41+00:00

How can I create a function with MATLAB so I can call it any

  • 0

How can I create a function with MATLAB so I can call it any where in my code?

I’m new to MATLAB so I will write a PHP example of the code I want to write in MATLAB!

    Function newmatlab(n){
    n=n+1;
    return n;
    }
array=array('1','2','3','4');
foreach($array as $x){
$result[]=newmatlab($x);
}
print_f($result);

So in nutshell, I need to loop an array and apply a function to each item in this array.

Can some one show me the above function written in MATLAB so I can understand better?

Note: I need this because I wrote a code that analyzes a video file and then plots data on a graph. I then and save this graph into Excel and jpg. My problem is that I have more than 200 video to analyze, so I need to automate this code to loop inside folders and analyze each *.avi file inside and etc.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T14:55:42+00:00Added an answer on May 28, 2026 at 2:55 pm

    As others have said, the documentation covers this pretty thoroughly, but perhaps we can help you understand.

    There are a handful of ways that you can define functions in Matlab, but probably the most useful for you to get started is to define one in an m-file. I’ll use your example code. You can do this by creating a file called newmatlab.m in your project’s directory that looks something like this

    % newmatlab.m
    function result = newmatlab(array)
    result = array + 1
    

    Note that the function has the same name as the file and that there is no explicit return statement – it figures that out by what you’ve named the output parameter(s) (result in this case).

    Then, in the same directory, you can create a script (or another function) that calls your newmatlab function by that name:

    % main.m (or whatever)
    a = [1 2 3 4];
    b = newmatlab(a)
    

    That’s it! This is a simplified explanation, but hopefully enough to get you started and then the documentation can help more.

    PS: There’s no “include” in Matlab; any functions that are defined in m-files in the current path are visible. You can find out what’s in the path by using the path command. Roughly, it’s going to consist of

    1. Matlab’s own directory
    2. The MATLAB subdirectory of your Documents directory
    3. The current working directory
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to create a simple menu function which can call it example get_menu()
How can I create a function that will have a dynamic return type based
I can create function pointers in Fortran 90, with code like real, external ::
I'm looking for a PHP library/function/class which can create Identicon s.
It's possible to call C functions through CREATE FUNCTION but how can .NET functions
I'm looking to create a PHP function that can trim each line in a
I would like to know how to create a php function that can be
I am new to MATLAB, and I can't fathom this from the documentation. function
If I use the inline function in MATLAB I can create a single function
In C++ you can create a function type with for example: void main() {

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.