Running C in Matlab

Post Reply
Joseph Bundala
Expert Member
Reactions: 23
Posts: 55
Joined: 7 years ago
Has thanked: 14 times
Been thanked: 28 times
Contact:

#1

  1. % This is MATLAB CODE with file name Hello.m
  2. %Print out is "Hello World"
  3. function Hello()
  4. fprintf('Hello World\n')
  5. end

==> Now, below is a C- code (Hello.c) in MATLAB to print same words but with the header "mex.h" and mexFunction (link to C main() function)
  1. #include "mex.h"
  2. void mexFunction(int nhls, mxArray *plhs[],
  3.         int nrhs, const mxArray *prhs[])        
  4. {
  5.     mexPrintf("Hello World\n");
  6.     }

To run Hello.c in MATLAB, type the below on the console.
  1. mex -setup   % Choose the compiler among the list, if not available then install.
  2. mex Hello.c  % will run the C program

0
Post Reply

Return to “MATLAB/Octave”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 0 guests