On 11/03/2017 03:47 PM, Eric Ludlam wrote:
Ah,  sorry I can't be more help.  It has been many years since I worked on that code, and I don't use Emacs much anymore.  There are accommodations in the function's I referenced for the ML command line to make sure it doesn't interrupting anything a user might be typing in that would be important for your use case.


Ok fair enough. I think I made some progress but still have a small
problem, maybe you might remember and  help. :-D

John's code consists of:

    - cleaning the matlab code in orgmode mode: (font lock stuff etc)
       and collect it.

    -  create a temporally file and insert the clean matlab commands.

    -  run a external matlab process via
       "/usr/local/bin/matlab " "-nodesktop <" m-file

    -  clean the result and insert it in the original buffer.

So my solution is to use the matlab-shell-collect-command-output
function. So my code is:

    - cleaning the matlab code in orgmode mode: (font lock stuff etc)
       and collect it.

    - run (matlab-shell-collect-command-output code) where code
       corresponds to the clean code from step one which John inserts in
       temp buffer.

    -  clean the result and insert it in the original buffer.


The only problem is that the output of the
       /usr/local/bin/matlab  -nodesktop < m-file

And (matlab-shell-collect-command-output code)
is slightly different.
Take the following example.

f=@(t,y)[-t*y^2];
[t,y]=ode45(f,[0 1],1);
t=[t(1),t(end)];
y=[y(1),y(end)];
disp('\begin{align*}')
fprintf('t = [%g  \\quad %g]  \\\\\n', t)
fprintf('y = [%g  \\qquad %g] \n', y)
disp('\end{align*}')

The external matlab command does not include the fprintf in his output.
I have collected the output of both approaches including the result of
the cleaning function.

So there are two possibilities.

    -  Modify matlab-shell-collect-command-output so that it behaves closer to
       /usr/local/bin/matlab -nodesktop < m-file

    -  modify the cleaning function (which I don't understand but could
       ask John about it).

      (when results
    ;; strip out >>
    (setq results (replace-regexp-in-string ">> " "" results))
    ;; remove first 10 lines that are the header.
    (setq results (mapconcat 'identity
                 (nthcdr 10 (split-string results "\n"))
                 "\n")))


Any comment is more than welcome. Here is the output of both commands



Uwe

1 Matlab and the cleaning

1.1 Result Matlab (John)

Result: "\n< M A T L A B (R) >\nCopyright 1984-2012 The MathWorks, Inc.\nR2012a (7.14.0.739) 32-bit (glnx86)\nFebruary 9, 2012\n\n\nToget started, type one of these: helpwin, helpdesk, or demo.\nForproduct information, visit www.mathworks.com.\n\n>> >> >> >> >> \\begin{align*}\n>> t = [0 \\quad1] \\\\\n>> y = [1 \\qquad0.666667] \n>> \\end{align*}\n>> "
Stop
[2 times]
Result: "\n< M A T L A B (R) >\nCopyright 1984-2012 The MathWorks, Inc.\nR2012a (7.14.0.739) 32-bit (glnx86)\nFebruary 9, 2012\n\n\nToget started, type one of these: helpwin, helpdesk, or demo.\nForproduct information, visit www.mathworks.com.\n\n>> >> >> >> >> \\begin{align*}\n>> t = [0 \\quad1] \\\\\n>> y = [1 \\qquad0.666667] \n>> \\end{align*}\n>> "
[3 times]
Result: "\n< M A T L A B (R) >\nCopyright 1984-2012 The MathWorks, Inc.\nR2012a (7.14.0.739) 32-bit (glnx86)\nFebruary 9, 2012\n\n\nToget started, type one of these: helpwin, helpdesk, or demo.\nForproduct information, visit www.mathworks.com.\n\n>> >> >> >> >> \\begin{align*}\n>> t = [0 \\quad1] \\\\\n>> y = [1 \\qquad0.666667] \n>> \\end{align*}\n>> "

Result: "\n< M A T L A B (R) >\nCopyright 1984-2012 The MathWorks, Inc.\nR2012a (7.14.0.739) 32-bit (glnx86)\nFebruary 9, 2012\n\n\nToget started, type one of these: helpwin, helpdesk, or demo.\nForproduct information, visit www.mathworks.com.\n\n\\begin{align*}\nt= [0 \\quad1] \\\\\ny= [1 \\qquad0.666667] \n\\end{align*}\n"

Result: "\n< M A T L A B (R) >\nCopyright 1984-2012 The MathWorks, Inc.\nR2012a (7.14.0.739) 32-bit (glnx86)\nFebruary 9, 2012\n\n\nToget started, type one of these: helpwin, helpdesk, or demo.\nForproduct information, visit www.mathworks.com.\n\n\\begin{align*}\nt= [0 \\quad1] \\\\\ny= [1 \\qquad0.666667] \n\\end{align*}\n"
[5 times]
Result: "\n< M A T L A B (R) >\nCopyright 1984-2012 The MathWorks, Inc.\nR2012a (7.14.0.739) 32-bit (glnx86)\nFebruary 9, 2012\n\n\nToget started, type one of these: helpwin, helpdesk, or demo.\nForproduct information, visit www.mathworks.com.\n\n\\begin{align*}\nt= [0 \\quad1] \\\\\ny= [1 \\qquad0.666667] \n\\end{align*}\n"

Result: (#1="" " < M A T L A B (R) >" " Copyright 1984-2012 The MathWorks, Inc." " R2012a (7.14.0.739) 32-bit (glnx86)" " February 9, 2012" #1# " " "To get started, type one of these: helpwin, helpdesk, or demo." "For product information, visit www.mathworks.com." " " "\\begin{align*}" "t = [0 \\quad1] \\\\" "y = [1 \\qquad0.666667] " "\\end{align*}" #1#)

1.2 Result cleaning (John)

Result: ("\\begin{align*}" "t = [0 \\quad1] \\\\" "y = [1 \\qquad0.666667] " "\\end{align*}" "")

Result: "\\begin{align*}\nt= [0 \\quad1] \\\\\ny= [1 \\qquad0.666667] \n\\end{align*}\n"

Result: "\\begin{align*}\nt= [0 \\quad1] \\\\\ny= [1 \\qquad0.666667] \n\\end{align*}\n"

Result: "\\begin{align*}\nt= [0 \\quad1] \\\\\ny= [1 \\qquad0.666667] \n\\end{align*}\n"
[2 times]
Result: ("replace" "output" "latex")

Result: "\\begin{align*}\nt= [0 \\quad1] \\\\\ny= [1 \\qquad0.666667] \n\\end{align*}\n"

Result: "\\begin{align*}\nt= [0 \\quad1] \\\\\ny= [1 \\qquad0.666667] \n\\end{align*}\n"

Result: "\\begin{align*}\nt= [0 \\quad1] \\\\\ny= [1 \\qquad0.666667] \n\\end{align*}\n"

Result: "\\begin{align*}\nt= [0 \\quad1] \\\\\ny= [1 \\qquad0.666667] \n\\end{align*}\n"

1.3 Result Matlab (Shell)

Result: "f=@(t,y)[-t*y2];\n[t,y]=ode45(f,[0 1],1);\nt=[t(1),t(end)];\ny=[y(1),y(end)];\ndisp('\\begin{align*}')\nfprintf('t = [%g \\\\quad%g] \\\\\\\\\\n', t)\nfprintf('y = [%g \\\\qquad%g] \\n', y)\ndisp('\\end{align*}')\n"

Result: ">> [t,y]=ode45(f,[0 1],1);\n>> t=[t(1),t(end)];\n>> y=[y(1),y(end)];\n>> disp('\\begin{align*}')\n\\begin{align*}\n>> fprintf('t = [%g \\\\quad%g] \\\\\\\\\\n', t)\nt= [0 \\quad1] \\\\\n>> fprintf('y = [%g \\\\qquad%g] \\n', y)\ny= [1 \\qquad0.666667] \n>> disp('\\end{align*}')\n\\end{align*}\n>> \n>> \n"
[2 times]
Result: ">> [t,y]=ode45(f,[0 1],1);\n>> t=[t(1),t(end)];\n>> y=[y(1),y(end)];\n>> disp('\\begin{align*}')\n\\begin{align*}\n>> fprintf('t = [%g \\\\quad%g] \\\\\\\\\\n', t)\nt= [0 \\quad1] \\\\\n>> fprintf('y = [%g \\\\qquad%g] \\n', y)\ny= [1 \\qquad0.666667] \n>> disp('\\end{align*}')\n\\end{align*}\n>> \n>> \n"
[3 times]
Result: ">> [t,y]=ode45(f,[0 1],1);\n>> t=[t(1),t(end)];\n>> y=[y(1),y(end)];\n>> disp('\\begin{align*}')\n\\begin{align*}\n>> fprintf('t = [%g \\\\quad%g] \\\\\\\\\\n', t)\nt= [0 \\quad1] \\\\\n>> fprintf('y = [%g \\\\qquad%g] \\n', y)\ny= [1 \\qquad0.666667] \n>> disp('\\end{align*}')\n\\end{align*}\n>> \n>> \n"

Result: "[t,y]=ode45(f,[0 1],1);\nt=[t(1),t(end)];\ny=[y(1),y(end)];\ndisp('\\begin{align*}')\n\\begin{align*}\nfprintf('t = [%g \\\\quad%g] \\\\\\\\\\n', t)\nt= [0 \\quad1] \\\\\nfprintf('y = [%g \\\\qquad%g] \\n', y)\ny= [1 \\qquad0.666667] \ndisp('\\end{align*}')\n\\end{align*}\n\n\n"

Result: "[t,y]=ode45(f,[0 1],1);\nt=[t(1),t(end)];\ny=[y(1),y(end)];\ndisp('\\begin{align*}')\n\\begin{align*}\nfprintf('t = [%g \\\\quad%g] \\\\\\\\\\n', t)\nt= [0 \\quad1] \\\\\nfprintf('y = [%g \\\\qquad%g] \\n', y)\ny= [1 \\qquad0.666667] \ndisp('\\end{align*}')\n\\end{align*}\n\n\n"
[5 times]
Result: "[t,y]=ode45(f,[0 1],1);\nt=[t(1),t(end)];\ny=[y(1),y(end)];\ndisp('\\begin{align*}')\n\\begin{align*}\nfprintf('t = [%g \\\\quad%g] \\\\\\\\\\n', t)\nt= [0 \\quad1] \\\\\nfprintf('y = [%g \\\\qquad%g] \\n', y)\ny= [1 \\qquad0.666667] \ndisp('\\end{align*}')\n\\end{align*}\n\n\n"

Result: ("[t,y]=ode45(f,[0 1],1);" "t=[t(1),t(end)];" "y=[y(1),y(end)];" "disp('\\begin{align*}')" "\\begin{align*}" "fprintf('t = [%g \\\\quad%g] \\\\\\\\\\n', t)" "t = [0 \\quad1] \\\\" "fprintf('y = [%g \\\\qquad%g] \\n', y)" "y = [1 \\qquad0.666667] " "disp('\\end{align*}')" "\\end{align*}" #1="" #1# #1#)

1.4 Result cleaning

Result: ("t=[t(1),t(end)];" "y=[y(1),y(end)];" "disp('\\begin{align*}')" "\\begin{align*}" "fprintf('t = [%g \\\\quad%g] \\\\\\\\\\n', t)" "t = [0 \\quad1] \\\\" "fprintf('y = [%g \\\\qquad%g] \\n', y)" "y = [1 \\qquad0.666667] " "disp('\\end{align*}')" "\\end{align*}" #1="" #1# #1#)

Result: "t=[t(1),t(end)];\ny=[y(1),y(end)];\ndisp('\\begin{align*}')\n\\begin{align*}\nfprintf('t = [%g \\\\quad%g] \\\\\\\\\\n', t)\nt= [0 \\quad1] \\\\\nfprintf('y = [%g \\\\qquad%g] \\n', y)\ny= [1 \\qquad0.666667] \ndisp('\\end{align*}')\n\\end{align*}\n\n\n"

Result: "t=[t(1),t(end)];\ny=[y(1),y(end)];\ndisp('\\begin{align*}')\n\\begin{align*}\nfprintf('t = [%g \\\\quad%g] \\\\\\\\\\n', t)\nt= [0 \\quad1] \\\\\nfprintf('y = [%g \\\\qquad%g] \\n', y)\ny= [1 \\qquad0.666667] \ndisp('\\end{align*}')\n\\end{align*}\n\n\n"

Result: "t=[t(1),t(end)];\ny=[y(1),y(end)];\ndisp('\\begin{align*}')\n\\begin{align*}\nfprintf('t = [%g \\\\quad%g] \\\\\\\\\\n', t)\nt= [0 \\quad1] \\\\\nfprintf('y = [%g \\\\qquad%g] \\n', y)\ny= [1 \\qquad0.666667] \ndisp('\\end{align*}')\n\\end{align*}\n\n\n"

Created: 2017-11-04 Sat 15:26

Validate


1 Matlab and the cleaning

1.1 Result Matlab (John)

Result: "\n< M A T L A B (R) >\nCopyright 1984-2012 The MathWorks, Inc.\nR2012a (7.14.0.739) 32-bit (glnx86)\nFebruary 9, 2012\n\n\nToget started, type one of these: helpwin, helpdesk, or demo.\nForproduct information, visit www.mathworks.com.\n\n>> >> >> >> >> \\begin{align*}\n>> t = [0 \\quad1] \\\\\n>> y = [1 \\qquad0.666667] \n>> \\end{align*}\n>> "
Stop
[2 times]
Result: "\n< M A T L A B (R) >\nCopyright 1984-2012 The MathWorks, Inc.\nR2012a (7.14.0.739) 32-bit (glnx86)\nFebruary 9, 2012\n\n\nToget started, type one of these: helpwin, helpdesk, or demo.\nForproduct information, visit www.mathworks.com.\n\n>> >> >> >> >> \\begin{align*}\n>> t = [0 \\quad1] \\\\\n>> y = [1 \\qquad0.666667] \n>> \\end{align*}\n>> "
[3 times]
Result: "\n< M A T L A B (R) >\nCopyright 1984-2012 The MathWorks, Inc.\nR2012a (7.14.0.739) 32-bit (glnx86)\nFebruary 9, 2012\n\n\nToget started, type one of these: helpwin, helpdesk, or demo.\nForproduct information, visit www.mathworks.com.\n\n>> >> >> >> >> \\begin{align*}\n>> t = [0 \\quad1] \\\\\n>> y = [1 \\qquad0.666667] \n>> \\end{align*}\n>> "

Result: "\n< M A T L A B (R) >\nCopyright 1984-2012 The MathWorks, Inc.\nR2012a (7.14.0.739) 32-bit (glnx86)\nFebruary 9, 2012\n\n\nToget started, type one of these: helpwin, helpdesk, or demo.\nForproduct information, visit www.mathworks.com.\n\n\\begin{align*}\nt= [0 \\quad1] \\\\\ny= [1 \\qquad0.666667] \n\\end{align*}\n"

Result: "\n< M A T L A B (R) >\nCopyright 1984-2012 The MathWorks, Inc.\nR2012a (7.14.0.739) 32-bit (glnx86)\nFebruary 9, 2012\n\n\nToget started, type one of these: helpwin, helpdesk, or demo.\nForproduct information, visit www.mathworks.com.\n\n\\begin{align*}\nt= [0 \\quad1] \\\\\ny= [1 \\qquad0.666667] \n\\end{align*}\n"
[5 times]
Result: "\n< M A T L A B (R) >\nCopyright 1984-2012 The MathWorks, Inc.\nR2012a (7.14.0.739) 32-bit (glnx86)\nFebruary 9, 2012\n\n\nToget started, type one of these: helpwin, helpdesk, or demo.\nForproduct information, visit www.mathworks.com.\n\n\\begin{align*}\nt= [0 \\quad1] \\\\\ny= [1 \\qquad0.666667] \n\\end{align*}\n"

Result: (#1="" " < M A T L A B (R) >" " Copyright 1984-2012 The MathWorks, Inc." " R2012a (7.14.0.739) 32-bit (glnx86)" " February 9, 2012" #1# " " "To get started, type one of these: helpwin, helpdesk, or demo." "For product information, visit www.mathworks.com." " " "\\begin{align*}" "t = [0 \\quad1] \\\\" "y = [1 \\qquad0.666667] " "\\end{align*}" #1#)

1.2 Result cleaning (John)

Result: ("\\begin{align*}" "t = [0 \\quad1] \\\\" "y = [1 \\qquad0.666667] " "\\end{align*}" "")

Result: "\\begin{align*}\nt= [0 \\quad1] \\\\\ny= [1 \\qquad0.666667] \n\\end{align*}\n"

Result: "\\begin{align*}\nt= [0 \\quad1] \\\\\ny= [1 \\qquad0.666667] \n\\end{align*}\n"

Result: "\\begin{align*}\nt= [0 \\quad1] \\\\\ny= [1 \\qquad0.666667] \n\\end{align*}\n"
[2 times]
Result: ("replace" "output" "latex")

Result: "\\begin{align*}\nt= [0 \\quad1] \\\\\ny= [1 \\qquad0.666667] \n\\end{align*}\n"

Result: "\\begin{align*}\nt= [0 \\quad1] \\\\\ny= [1 \\qquad0.666667] \n\\end{align*}\n"

Result: "\\begin{align*}\nt= [0 \\quad1] \\\\\ny= [1 \\qquad0.666667] \n\\end{align*}\n"

Result: "\\begin{align*}\nt= [0 \\quad1] \\\\\ny= [1 \\qquad0.666667] \n\\end{align*}\n"

1.3 Result Matlab (Shell)

Result: "f=@(t,y)[-t*y2];\n[t,y]=ode45(f,[0 1],1);\nt=[t(1),t(end)];\ny=[y(1),y(end)];\ndisp('\\begin{align*}')\nfprintf('t = [%g \\\\quad%g] \\\\\\\\\\n', t)\nfprintf('y = [%g \\\\qquad%g] \\n', y)\ndisp('\\end{align*}')\n"

Result: ">> [t,y]=ode45(f,[0 1],1);\n>> t=[t(1),t(end)];\n>> y=[y(1),y(end)];\n>> disp('\\begin{align*}')\n\\begin{align*}\n>> fprintf('t = [%g \\\\quad%g] \\\\\\\\\\n', t)\nt= [0 \\quad1] \\\\\n>> fprintf('y = [%g \\\\qquad%g] \\n', y)\ny= [1 \\qquad0.666667] \n>> disp('\\end{align*}')\n\\end{align*}\n>> \n>> \n"
[2 times]
Result: ">> [t,y]=ode45(f,[0 1],1);\n>> t=[t(1),t(end)];\n>> y=[y(1),y(end)];\n>> disp('\\begin{align*}')\n\\begin{align*}\n>> fprintf('t = [%g \\\\quad%g] \\\\\\\\\\n', t)\nt= [0 \\quad1] \\\\\n>> fprintf('y = [%g \\\\qquad%g] \\n', y)\ny= [1 \\qquad0.666667] \n>> disp('\\end{align*}')\n\\end{align*}\n>> \n>> \n"
[3 times]
Result: ">> [t,y]=ode45(f,[0 1],1);\n>> t=[t(1),t(end)];\n>> y=[y(1),y(end)];\n>> disp('\\begin{align*}')\n\\begin{align*}\n>> fprintf('t = [%g \\\\quad%g] \\\\\\\\\\n', t)\nt= [0 \\quad1] \\\\\n>> fprintf('y = [%g \\\\qquad%g] \\n', y)\ny= [1 \\qquad0.666667] \n>> disp('\\end{align*}')\n\\end{align*}\n>> \n>> \n"

Result: "[t,y]=ode45(f,[0 1],1);\nt=[t(1),t(end)];\ny=[y(1),y(end)];\ndisp('\\begin{align*}')\n\\begin{align*}\nfprintf('t = [%g \\\\quad%g] \\\\\\\\\\n', t)\nt= [0 \\quad1] \\\\\nfprintf('y = [%g \\\\qquad%g] \\n', y)\ny= [1 \\qquad0.666667] \ndisp('\\end{align*}')\n\\end{align*}\n\n\n"

Result: "[t,y]=ode45(f,[0 1],1);\nt=[t(1),t(end)];\ny=[y(1),y(end)];\ndisp('\\begin{align*}')\n\\begin{align*}\nfprintf('t = [%g \\\\quad%g] \\\\\\\\\\n', t)\nt= [0 \\quad1] \\\\\nfprintf('y = [%g \\\\qquad%g] \\n', y)\ny= [1 \\qquad0.666667] \ndisp('\\end{align*}')\n\\end{align*}\n\n\n"
[5 times]
Result: "[t,y]=ode45(f,[0 1],1);\nt=[t(1),t(end)];\ny=[y(1),y(end)];\ndisp('\\begin{align*}')\n\\begin{align*}\nfprintf('t = [%g \\\\quad%g] \\\\\\\\\\n', t)\nt= [0 \\quad1] \\\\\nfprintf('y = [%g \\\\qquad%g] \\n', y)\ny= [1 \\qquad0.666667] \ndisp('\\end{align*}')\n\\end{align*}\n\n\n"

Result: ("[t,y]=ode45(f,[0 1],1);" "t=[t(1),t(end)];" "y=[y(1),y(end)];" "disp('\\begin{align*}')" "\\begin{align*}" "fprintf('t = [%g \\\\quad%g] \\\\\\\\\\n', t)" "t = [0 \\quad1] \\\\" "fprintf('y = [%g \\\\qquad%g] \\n', y)" "y = [1 \\qquad0.666667] " "disp('\\end{align*}')" "\\end{align*}" #1="" #1# #1#)

1.4 Result cleaning

Result: ("t=[t(1),t(end)];" "y=[y(1),y(end)];" "disp('\\begin{align*}')" "\\begin{align*}" "fprintf('t = [%g \\\\quad%g] \\\\\\\\\\n', t)" "t = [0 \\quad1] \\\\" "fprintf('y = [%g \\\\qquad%g] \\n', y)" "y = [1 \\qquad0.666667] " "disp('\\end{align*}')" "\\end{align*}" #1="" #1# #1#)

Result: "t=[t(1),t(end)];\ny=[y(1),y(end)];\ndisp('\\begin{align*}')\n\\begin{align*}\nfprintf('t = [%g \\\\quad%g] \\\\\\\\\\n', t)\nt= [0 \\quad1] \\\\\nfprintf('y = [%g \\\\qquad%g] \\n', y)\ny= [1 \\qquad0.666667] \ndisp('\\end{align*}')\n\\end{align*}\n\n\n"

Result: "t=[t(1),t(end)];\ny=[y(1),y(end)];\ndisp('\\begin{align*}')\n\\begin{align*}\nfprintf('t = [%g \\\\quad%g] \\\\\\\\\\n', t)\nt= [0 \\quad1] \\\\\nfprintf('y = [%g \\\\qquad%g] \\n', y)\ny= [1 \\qquad0.666667] \ndisp('\\end{align*}')\n\\end{align*}\n\n\n"

Result: "t=[t(1),t(end)];\ny=[y(1),y(end)];\ndisp('\\begin{align*}')\n\\begin{align*}\nfprintf('t = [%g \\\\quad%g] \\\\\\\\\\n', t)\nt= [0 \\quad1] \\\\\nfprintf('y = [%g \\\\qquad%g] \\n', y)\ny= [1 \\qquad0.666667] \ndisp('\\end{align*}')\n\\end{align*}\n\n\n"

Created: 2017-11-04 Sat 15:26

Validate


Attachment: smime.p7s
Description: S/MIME Cryptographic Signature

------------------------------------------------------------------------------
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

Reply via email to