Simple mex question: how to call a mex function in matlab utilizing variables defined in matlab
Mostra commenti meno recenti
So I'm trying to convert pieces of a matlab program into mex files to increase the execution speed. The program has about 20 different matlab scripts in it. I'm relatively new to both c and matlab, how do I integrate the mex files into matlab? As an example, how do I rewrite this struct from .m to c to compile as mex to be used in the program?
function [local] = LocalInfo(Euler, k, q, qh, forcing)
% Extract local info for element k
% local struct
local = [];
local.force = feval(forcing, Euler, Euler.x(:,k));
local.q = squeeze(q(:,k,:));
local.q0 = squeeze(Euler.q0(:,k,:));
local.nx = Euler.nx(:,k);% normal vector
local.J = Euler.J(1,k);
local.rx = Euler.rx(1,k);
local.qh = reshape(qh(k:k+1,:),[],1);
local.k = k;
Thanks in advance
Risposta accettata
Più risposte (2)
Jan
il 15 Lug 2014
2 voti
This piece of code is processed efficiently in Matlab. If you call a mex-function, which calls Matlab again for the feval, a lot of time is spend in the overheads of the interfaces. Therefore I'm convinced that this piece of code is faster, when you leave it in Matlab.
Mukul Rao
il 14 Lug 2014
1 voto
Hi,
MEX files are used to run C/C++ or Fortran codes in the MATLAB environment. This means that if you have an existing C code that you would like to execute in the MATLAB environment, you would have to first convert it to a MEX file by making certain changes, described in detail in the links below:
I assume that you have a few MATLAB scripts that you would like to run as a C application? In that case what would work best for you is the MATLAB Compiler toolbox. MATLAB Compiler can convert MATLAB code into a standalone executable or C/C++ shared libraries. Please refer the following link to get introduced to the MATLAB compiler:
Categorie
Scopri di più su MATLAB Coder in Centro assistenza e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!