Hi, Assuming that matlab-mode and matlab-shell are working, org-babel natively supports matlab code execution.
Your org-babel-execute:matlab overrides the org-babel defaults in ob-octave.el, which can be inspected there. I enable the babel support in .emacs as (org-babel-do-load-languages 'org-babel-load-languages '( (latex . t) (plantuml . t) (java . t) (matlab . t) (C . t) (csharp . t) (table . t) ) ) after this, C-c C-c will execute the code, but the next snippet in .emacs makes the sessions continuous, and simplifies the arguments given each time (setq org-babel-default-header-args:matlab '((:session . "*MATLAB*") (:results . "silent") ) ) More an org answer than matlab.el, but I hope these help. Cumhur Erkut > On Oct 24, 2017, at 22:53, Uwe Brauer <o...@mat.ucm.es> wrote: > > Hi > > I am using more and more org mode, a long with auctex and matlab.el. > Orgmode comes in handy if I write a document which contains (matlab) > code which I want to execute, but the rest of the file maybe text, which > I can then export to latex. > > So a typical file looks like > > Given > \droppoints > \begin{displaymath} > \begin{cases} > \frac{du}{dt}&= -t u^2,\\ > u(0)&=1, > \end{cases} > \end{displaymath} > > Solve using ... > > > #+BEGIN_solution > #+begin_src matlab :results output latex :exports results :eval never-export > f=@(t,y)[-t*y^2]; > [t,y]=mieuler(f,[0 1],1,2); > disp('\begin{align*}') > fprintf('t = [%g \\qquad %g \\quad %g] \\\\\n', t) > fprintf('y = [%g \\qquad %g \\qquad %g] \n', y) > disp('\end{align*}') > #+end_src > > Now I can execute the matlab code in that org file using > > C-c C-c ( org-ctrl-c-ctrl-c, the *one-ring-to-rule-them-all* function in > orgmode. > > Thanks thanks to a function provided to me by John Kitchin it executes > matlab. > > It is as follows: > > (defun org-babel-execute:matlab (body params) > (interactive "P") > (let* ((current-file (buffer-file-name)) > (code (org-element-property :value (org-element-context))) > (result-params (cdr (assoc :result-params params))) > m-file > md5-hash) > (with-temp-buffer > (insert code) > (setq md5-hash (md5 (buffer-string)) > mbuffer (format "*m-%s*" md5-hash) > m-file (format "m-%s.m" md5-hash))) > ;; create the file to run > (with-temp-file m-file > (insert code)) > (let ((results (shell-command-to-string > (concat > "/usr/local/bin/matlab " > "-nodesktop -nojvm -nosplash -nodisplay <" > m-file)))) > (delete-file m-file) > (when results > ;; strip out >> > (setq results (replace-regexp-in-string ">> " "" results)) > ;; remove first 10 lines that are the header. > ;; matlab license seem to expire soon, so 5 warning lines are added > ;; change first 10 to first 15 lines > (setq results (mapconcat 'identity > (nthcdr 10 (split-string results "\n")) > "\n"))) > (org-babel-result-cond result-params > results)))) > > The problem of that code is that it starts matlab every time I execute > C-c C-c . There seems to be a python based kernel around which avoids > this, but I thought that maybe with a bit of hacking one could use the > elisp based matlab-shell and the corresponding functions. > > Anybody has an idea, Eric? > Needless to say that I played a bit around but did get it to work.... > > Regards > > Uwe Brauer > > > > ------------------------------------------------------------------------------ > Check out the vibrant tech community on one of the world's most > engaging tech sites, Slashdot.org! http://sdm.link/slashdot > _______________________________________________ > Matlab-emacs-discuss mailing list > Matlab-emacs-discuss@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/matlab-emacs-discuss ------------------------------------------------------------------------------ Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot _______________________________________________ Matlab-emacs-discuss mailing list Matlab-emacs-discuss@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matlab-emacs-discuss