emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* org-babel matlab example
@ 2010-09-11  9:18 etimecowboy
  2010-09-11 15:29 ` Dan Davison
  0 siblings, 1 reply; 11+ messages in thread
From: etimecowboy @ 2010-09-11  9:18 UTC (permalink / raw)
  To: emacs-orgmode

Hi everybody,

I am learning to use org-babel to evaluate in-line Matlab code block, but I cannot make it works when I press the "C-c C-c", nor "C-c C-v e". The export of code works, but the results was not there. My in-line code is like this:

#+begin_src matlab :export results
n = [1:10];
x = 5*n+4;
x
#+end_src

Is there someone can provide me a working example? Thanks a lot.


-----------------------------

etimecowboy@gmail.com

      _.,----,._
    .:'        `:.
  .'              `.
 .'                `.
 :                  :
 `    .'`':'`'`/    '
  `.   \  |   /   ,'
    \   \ |  /   /
     `\_..,,.._/'
      {`'-,_`'-}
      {`'-,_`'-}
      {`'-,_`'-}
       `YXXXXY'
         ~^^~

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: org-babel matlab example
  2010-09-11  9:18 org-babel matlab example etimecowboy
@ 2010-09-11 15:29 ` Dan Davison
  2010-09-11 16:23   ` Dan Davison
  0 siblings, 1 reply; 11+ messages in thread
From: Dan Davison @ 2010-09-11 15:29 UTC (permalink / raw)
  To: etimecowboy; +Cc: emacs-orgmode

etimecowboy <etimecowboy@googlemail.com> writes:

> Hi everybody,
>
> I am learning to use org-babel to evaluate in-line Matlab code block,
> but I cannot make it works when I press the "C-c C-c", nor "C-c C-v
> e".

What happens when you try C-c C-c or C-c C-v e ? There is an issue with
matlab and octave: they return the value of the last /unassigned/
computation, so simply ending the code block with a variable name "x" is
not enough. Could you try one of the following schemes please, and let
us know if that solves it:

#+begin_src matlab :exports results
n = [1:10];
x = 5*n+4;
ans = x
#+end_src

#+begin_src matlab :exports results
n = [1:10];
x = 5*n+4;
x + 0
#+end_src


> The export of code works, but the results was not there. My in-line code is like this:

There was a little typo in your original block: the keyword is
":exports" with an s.

Dan

>
> #+begin_src matlab :export results
> n = [1:10];
> x = 5*n+4;
> x
> #+end_src
>
> Is there someone can provide me a working example? Thanks a lot.
>
>
> -----------------------------
>
> etimecowboy@gmail.com
>
>       _.,----,._
>     .:'        `:.
>   .'              `.
>  .'                `.
>  :                  :
>  `    .'`':'`'`/    '
>   `.   \  |   /   ,'
>     \   \ |  /   /
>      `\_..,,.._/'
>       {`'-,_`'-}
>       {`'-,_`'-}
>       {`'-,_`'-}
>        `YXXXXY'
>          ~^^~
>
> _______________________________________________
> Emacs-orgmode mailing list
> Please use `Reply All' to send replies to the list.
> Emacs-orgmode@gnu.org
> http://lists.gnu.org/mailman/listinfo/emacs-orgmode

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: org-babel matlab example
  2010-09-11 15:29 ` Dan Davison
@ 2010-09-11 16:23   ` Dan Davison
  2010-09-12  7:45     ` etimecowboy
  0 siblings, 1 reply; 11+ messages in thread
From: Dan Davison @ 2010-09-11 16:23 UTC (permalink / raw)
  To: etimecowboy; +Cc: emacs-orgmode

Dan Davison <davison@stats.ox.ac.uk> writes:

> etimecowboy <etimecowboy@googlemail.com> writes:
>
>> Hi everybody,
>>
>> I am learning to use org-babel to evaluate in-line Matlab code block,
>> but I cannot make it works when I press the "C-c C-c", nor "C-c C-v
>> e".
>
> What happens when you try C-c C-c or C-c C-v e ? There is an issue with
> matlab and octave: they return the value of the last /unassigned/
> computation

A better way to say this is: they return the value of the special
variable "ans". So whatever you do, at the end of the block you need to
ensure that "ans" has the value that you want returned.

I've updated the Worg page on Matlab and Octave:

http://orgmode.org/worg/org-contrib/babel/languages/ob-doc-octave-matlab.php

Dan


>, so simply ending the code block with a variable name "x" is
> not enough. Could you try one of the following schemes please, and let
> us know if that solves it:
>
> #+begin_src matlab :exports results
> n = [1:10];
> x = 5*n+4;
> ans = x
> #+end_src
>
> #+begin_src matlab :exports results
> n = [1:10];
> x = 5*n+4;
> x + 0
> #+end_src
>
>
>> The export of code works, but the results was not there. My in-line code is like this:
>
> There was a little typo in your original block: the keyword is
> ":exports" with an s.
>
> Dan
>
>>
>> #+begin_src matlab :export results
>> n = [1:10];
>> x = 5*n+4;
>> x
>> #+end_src
>>
>> Is there someone can provide me a working example? Thanks a lot.
>>
>>
>> -----------------------------
>>
>> etimecowboy@gmail.com
>>
>>       _.,----,._
>>     .:'        `:.
>>   .'              `.
>>  .'                `.
>>  :                  :
>>  `    .'`':'`'`/    '
>>   `.   \  |   /   ,'
>>     \   \ |  /   /
>>      `\_..,,.._/'
>>       {`'-,_`'-}
>>       {`'-,_`'-}
>>       {`'-,_`'-}
>>        `YXXXXY'
>>          ~^^~
>>
>> _______________________________________________
>> Emacs-orgmode mailing list
>> Please use `Reply All' to send replies to the list.
>> Emacs-orgmode@gnu.org
>> http://lists.gnu.org/mailman/listinfo/emacs-orgmode
>
> _______________________________________________
> Emacs-orgmode mailing list
> Please use `Reply All' to send replies to the list.
> Emacs-orgmode@gnu.org
> http://lists.gnu.org/mailman/listinfo/emacs-orgmode

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: org-babel matlab example
  2010-09-11 16:23   ` Dan Davison
@ 2010-09-12  7:45     ` etimecowboy
  2010-09-12 14:58       ` Darlan Cavalcante Moreira
  0 siblings, 1 reply; 11+ messages in thread
From: etimecowboy @ 2010-09-12  7:45 UTC (permalink / raw)
  To: davison; +Cc: etimecowboy, emacs-orgmode

From: Dan Davison <davison@stats.ox.ac.uk>
Subject: Re: org-babel matlab example
Date: Sat, 11 Sep 2010 12:23:17 -0400

> Dan Davison <davison@stats.ox.ac.uk> writes:
> 
>> etimecowboy <etimecowboy@googlemail.com> writes:
>>
>>> Hi everybody,
>>>
>>> I am learning to use org-babel to evaluate in-line Matlab code block,
>>> but I cannot make it works when I press the "C-c C-c", nor "C-c C-v
>>> e".
>>
>> What happens when you try C-c C-c or C-c C-v e ? There is an issue with
>> matlab and octave: they return the value of the last /unassigned/
>> computation
> 
> A better way to say this is: they return the value of the special
> variable "ans". So whatever you do, at the end of the block you need to
> ensure that "ans" has the value that you want returned.
> 
> I've updated the Worg page on Matlab and Octave:
> 
> http://orgmode.org/worg/org-contrib/babel/languages/ob-doc-octave-matlab.php
> 
> Dan
> 
> 
>>, so simply ending the code block with a variable name "x" is
>> not enough. Could you try one of the following schemes please, and let
>> us know if that solves it:
>>
>> #+begin_src matlab :exports results
>> n = [1:10];
>> x = 5*n+4;
>> ans = x
>> #+end_src
>>
>> #+begin_src matlab :exports results
>> n = [1:10];
>> x = 5*n+4;
>> x + 0
>> #+end_src
>>
>>
>>> The export of code works, but the results was not there. My in-line code is like this:
>>
>> There was a little typo in your original block: the keyword is
>> ":exports" with an s.
>>
>> Dan
>>
>>>
>>> #+begin_src matlab :export results
>>> n = [1:10];
>>> x = 5*n+4;
>>> x
>>> #+end_src
>>>
>>> Is there someone can provide me a working example? Thanks a lot.
>>>
>>>
>>> -----------------------------
>>>
>>> etimecowboy@gmail.com
>>>
>>>       _.,----,._
>>>     .:'        `:.
>>>   .'              `.
>>>  .'                `.
>>>  :                  :
>>>  `    .'`':'`'`/    '
>>>   `.   \  |   /   ,'
>>>     \   \ |  /   /
>>>      `\_..,,.._/'
>>>       {`'-,_`'-}
>>>       {`'-,_`'-}
>>>       {`'-,_`'-}
>>>        `YXXXXY'
>>>          ~^^~
>>>
>>> _______________________________________________
>>> Emacs-orgmode mailing list
>>> Please use `Reply All' to send replies to the list.
>>> Emacs-orgmode@gnu.org
>>> http://lists.gnu.org/mailman/listinfo/emacs-orgmode
>>
>> _______________________________________________
>> Emacs-orgmode mailing list
>> Please use `Reply All' to send replies to the list.
>> Emacs-orgmode@gnu.org
>> http://lists.gnu.org/mailman/listinfo/emacs-orgmode

Dear Dan,

I have checked the Worg page you updated and tried your example. It works! The ans variable is the secret! Thanks a lot. I suggest org should provide some examples in its user's guide, not only on the topic of Babel but also Table, Hyperlink, Picture, and etc.

-----------------------------

etimecowboy@gmail.com

      _.,----,._
    .:'        `:.
  .'              `.
 .'                `.
 :                  :
 `    .'`':'`'`/    '
  `.   \  |   /   ,'
    \   \ |  /   /
     `\_..,,.._/'
      {`'-,_`'-}
      {`'-,_`'-}
      {`'-,_`'-}
       `YXXXXY'
         ~^^~

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Re: org-babel matlab example
  2010-09-12  7:45     ` etimecowboy
@ 2010-09-12 14:58       ` Darlan Cavalcante Moreira
  2010-09-14 15:40         ` Dan Davison
  0 siblings, 1 reply; 11+ messages in thread
From: Darlan Cavalcante Moreira @ 2010-09-12 14:58 UTC (permalink / raw)
  To: etimecowboy; +Cc: davison, emacs-orgmode


Can I leave a suggestion here?
Maybe a header argument
,----
| :return variableName
`----
could be interesting in org babel. This would make babel behavior more
uniform in all supported languages and avoid the necessity of adding code
"only to make babel work".

--
Darlan

At Sun, 12 Sep 2010 08:45:40 +0100 (BST),
etimecowboy <etimecowboy@googlemail.com> wrote:
> 
> From: Dan Davison <davison@stats.ox.ac.uk>
> Subject: Re: org-babel matlab example
> Date: Sat, 11 Sep 2010 12:23:17 -0400
> 
> > Dan Davison <davison@stats.ox.ac.uk> writes:
> > 
> >> etimecowboy <etimecowboy@googlemail.com> writes:
> >>
> >>> Hi everybody,
> >>>
> >>> I am learning to use org-babel to evaluate in-line Matlab code block,
> >>> but I cannot make it works when I press the "C-c C-c", nor "C-c C-v
> >>> e".
> >>
> >> What happens when you try C-c C-c or C-c C-v e ? There is an issue with
> >> matlab and octave: they return the value of the last /unassigned/
> >> computation
> > 
> > A better way to say this is: they return the value of the special
> > variable "ans". So whatever you do, at the end of the block you need to
> > ensure that "ans" has the value that you want returned.
> > 
> > I've updated the Worg page on Matlab and Octave:
> > 
> > http://orgmode.org/worg/org-contrib/babel/languages/ob-doc-octave-matlab.php
> > 
> > Dan
> > 
> > 
> >>, so simply ending the code block with a variable name "x" is
> >> not enough. Could you try one of the following schemes please, and let
> >> us know if that solves it:
> >>
> >> #+begin_src matlab :exports results
> >> n = [1:10];
> >> x = 5*n+4;
> >> ans = x
> >> #+end_src
> >>
> >> #+begin_src matlab :exports results
> >> n = [1:10];
> >> x = 5*n+4;
> >> x + 0
> >> #+end_src
> >>
> >>
> >>> The export of code works, but the results was not there. My in-line code is like this:
> >>
> >> There was a little typo in your original block: the keyword is
> >> ":exports" with an s.
> >>
> >> Dan
> >>
> >>>
> >>> #+begin_src matlab :export results
> >>> n = [1:10];
> >>> x = 5*n+4;
> >>> x
> >>> #+end_src
> >>>
> >>> Is there someone can provide me a working example? Thanks a lot.
> >>>
> >>>
> >>> -----------------------------
> >>>
> >>> etimecowboy@gmail.com
> >>>
> >>>       _.,----,._
> >>>     .:'        `:.
> >>>   .'              `.
> >>>  .'                `.
> >>>  :                  :
> >>>  `    .'`':'`'`/    '
> >>>   `.   \  |   /   ,'
> >>>     \   \ |  /   /
> >>>      `\_..,,.._/'
> >>>       {`'-,_`'-}
> >>>       {`'-,_`'-}
> >>>       {`'-,_`'-}
> >>>        `YXXXXY'
> >>>          ~^^~
> >>>
> >>> _______________________________________________
> >>> Emacs-orgmode mailing list
> >>> Please use `Reply All' to send replies to the list.
> >>> Emacs-orgmode@gnu.org
> >>> http://lists.gnu.org/mailman/listinfo/emacs-orgmode
> >>
> >> _______________________________________________
> >> Emacs-orgmode mailing list
> >> Please use `Reply All' to send replies to the list.
> >> Emacs-orgmode@gnu.org
> >> http://lists.gnu.org/mailman/listinfo/emacs-orgmode
> 
> Dear Dan,
> 
> I have checked the Worg page you updated and tried your example. It works! The ans variable is the secret! Thanks a lot. I suggest org should provide some examples in its user's guide, not only on the topic of Babel but also Table, Hyperlink, Picture, and etc.
> 
> -----------------------------
> 
> etimecowboy@gmail.com
> 
>       _.,----,._
>     .:'        `:.
>   .'              `.
>  .'                `.
>  :                  :
>  `    .'`':'`'`/    '
>   `.   \  |   /   ,'
>     \   \ |  /   /
>      `\_..,,.._/'
>       {`'-,_`'-}
>       {`'-,_`'-}
>       {`'-,_`'-}
>        `YXXXXY'
>          ~^^~
> 
> _______________________________________________
> Emacs-orgmode mailing list
> Please use `Reply All' to send replies to the list.
> Emacs-orgmode@gnu.org
> http://lists.gnu.org/mailman/listinfo/emacs-orgmode

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Re: org-babel matlab example
  2010-09-12 14:58       ` Darlan Cavalcante Moreira
@ 2010-09-14 15:40         ` Dan Davison
  2010-09-14 18:19           ` Achim Gratz
  2010-09-14 18:23           ` Darlan Cavalcante Moreira
  0 siblings, 2 replies; 11+ messages in thread
From: Dan Davison @ 2010-09-14 15:40 UTC (permalink / raw)
  To: Darlan Cavalcante Moreira; +Cc: etimecowboy, emacs-orgmode

Darlan Cavalcante Moreira <darcamo@gmail.com> writes:

> Can I leave a suggestion here?
> Maybe a header argument
> ,----
> | :return variableName
> `----
> could be interesting in org babel. This would make babel behavior more
> uniform in all supported languages and avoid the necessity of adding code
> "only to make babel work".

Hi Darlan,

Thanks (and sorry if you've made this suggestion previously, which I
seem to recall). I can see that this would be particularly natural for
matlab/octave in which (aIui) function definitions require specifying
the name of the variable whose value is to be returned. In other
languages which I've encountered, return values are determined by either
"return" statements, or the value of the last statement in the function,
or both of these mechanisms. So if we were to apply your suggestion to
all languages, one could argue that it would permit un-natural code in
languages other than matlab/octave. As you say, we do want things to be
uniform across languages, but perhaps there is an argument for
restricting your suggestion to matlab/octave?

Dan

>
> --
> Darlan
>
> At Sun, 12 Sep 2010 08:45:40 +0100 (BST),
> etimecowboy <etimecowboy@googlemail.com> wrote:
>> 
>> From: Dan Davison <davison@stats.ox.ac.uk>
>> Subject: Re: org-babel matlab example
>> Date: Sat, 11 Sep 2010 12:23:17 -0400
>> 
>> > Dan Davison <davison@stats.ox.ac.uk> writes:
>> > 
>> >> etimecowboy <etimecowboy@googlemail.com> writes:
>> >>
>> >>> Hi everybody,
>> >>>
>> >>> I am learning to use org-babel to evaluate in-line Matlab code block,
>> >>> but I cannot make it works when I press the "C-c C-c", nor "C-c C-v
>> >>> e".
>> >>
>> >> What happens when you try C-c C-c or C-c C-v e ? There is an issue with
>> >> matlab and octave: they return the value of the last /unassigned/
>> >> computation
>> > 
>> > A better way to say this is: they return the value of the special
>> > variable "ans". So whatever you do, at the end of the block you need to
>> > ensure that "ans" has the value that you want returned.
>> > 
>> > I've updated the Worg page on Matlab and Octave:
>> > 
>> > http://orgmode.org/worg/org-contrib/babel/languages/ob-doc-octave-matlab.php
>> > 
>> > Dan
>> > 
>> > 
>> >>, so simply ending the code block with a variable name "x" is
>> >> not enough. Could you try one of the following schemes please, and let
>> >> us know if that solves it:
>> >>
>> >> #+begin_src matlab :exports results
>> >> n = [1:10];
>> >> x = 5*n+4;
>> >> ans = x
>> >> #+end_src
>> >>
>> >> #+begin_src matlab :exports results
>> >> n = [1:10];
>> >> x = 5*n+4;
>> >> x + 0
>> >> #+end_src
>> >>
>> >>
>> >>> The export of code works, but the results was not there. My in-line code is like this:
>> >>
>> >> There was a little typo in your original block: the keyword is
>> >> ":exports" with an s.
>> >>
>> >> Dan
>> >>
>> >>>
>> >>> #+begin_src matlab :export results
>> >>> n = [1:10];
>> >>> x = 5*n+4;
>> >>> x
>> >>> #+end_src
>> >>>
>> >>> Is there someone can provide me a working example? Thanks a lot.
>> >>>
>> >>>
>> >>> -----------------------------
>> >>>
>> >>> etimecowboy@gmail.com
>> >>>
>> >>>       _.,----,._
>> >>>     .:'        `:.
>> >>>   .'              `.
>> >>>  .'                `.
>> >>>  :                  :
>> >>>  `    .'`':'`'`/    '
>> >>>   `.   \  |   /   ,'
>> >>>     \   \ |  /   /
>> >>>      `\_..,,.._/'
>> >>>       {`'-,_`'-}
>> >>>       {`'-,_`'-}
>> >>>       {`'-,_`'-}
>> >>>        `YXXXXY'
>> >>>          ~^^~
>> >>>
>> >>> _______________________________________________
>> >>> Emacs-orgmode mailing list
>> >>> Please use `Reply All' to send replies to the list.
>> >>> Emacs-orgmode@gnu.org
>> >>> http://lists.gnu.org/mailman/listinfo/emacs-orgmode
>> >>
>> >> _______________________________________________
>> >> Emacs-orgmode mailing list
>> >> Please use `Reply All' to send replies to the list.
>> >> Emacs-orgmode@gnu.org
>> >> http://lists.gnu.org/mailman/listinfo/emacs-orgmode
>> 
>> Dear Dan,
>> 
>> I have checked the Worg page you updated and tried your example. It works! The ans variable is the secret! Thanks a lot. I suggest org should provide some examples in its user's guide, not only on the topic of Babel but also Table, Hyperlink, Picture, and etc.
>> 
>> -----------------------------
>> 
>> etimecowboy@gmail.com
>> 
>>       _.,----,._
>>     .:'        `:.
>>   .'              `.
>>  .'                `.
>>  :                  :
>>  `    .'`':'`'`/    '
>>   `.   \  |   /   ,'
>>     \   \ |  /   /
>>      `\_..,,.._/'
>>       {`'-,_`'-}
>>       {`'-,_`'-}
>>       {`'-,_`'-}
>>        `YXXXXY'
>>          ~^^~
>> 
>> _______________________________________________
>> Emacs-orgmode mailing list
>> Please use `Reply All' to send replies to the list.
>> Emacs-orgmode@gnu.org
>> http://lists.gnu.org/mailman/listinfo/emacs-orgmode

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: org-babel matlab example
  2010-09-14 15:40         ` Dan Davison
@ 2010-09-14 18:19           ` Achim Gratz
  2010-09-14 20:14             ` Achim Gratz
  2010-09-14 18:23           ` Darlan Cavalcante Moreira
  1 sibling, 1 reply; 11+ messages in thread
From: Achim Gratz @ 2010-09-14 18:19 UTC (permalink / raw)
  To: emacs-orgmode

Dan Davison <davison@stats.ox.ac.uk> writes:
> I can see that this would be particularly natural for
> matlab/octave in which (aIui) function definitions require specifying
> the name of the variable whose value is to be returned.

I can't say I fully understand what's going on and possibly I'm off my
rocker; but it seems to me that it is only the wrapper function from
ob-octave that requires the result to be anonymous so it can pick up on
"ans" without having to either parse the input or the output of Octave.
This is an artefact of how Octave handles things and a convention to
make things click with the wrapper in babel.  If for instance you'd wrap
the Octave script into an anonymous structure, you could get at the last
evaluation without knowing the name, like this:

: {%s};ans{size(ans,1)}

That'd remove the requirement of delivering the result in any particular
form as long as it is produced by the last evaluation in the code block.
I'm not sure it works when code sprinkled across several blocks is
supposed to be in a single session, however.

> In other languages which I've encountered, return values are
> determined by either "return" statements, or the value of the last
> statement in the function, or both of these mechanisms. So if we were
> to apply your suggestion to all languages, one could argue that it
> would permit un-natural code in languages other than matlab/octave. As
> you say, we do want things to be uniform across languages, but perhaps
> there is an argument for restricting your suggestion to matlab/octave?

A more interesting question is what should happen if the language in
question is capable of delivering multiple results on return...


Achim.
-- 
+<[Q+ Matrix-12 WAVE#46+305 Neuron microQkb Andromeda XTk Blofeld]>+

Factory and User Sound Singles for Waldorf rackAttack:
http://Synth.Stromeko.net/Downloads.html#WaldorfSounds

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Re: org-babel matlab example
  2010-09-14 15:40         ` Dan Davison
  2010-09-14 18:19           ` Achim Gratz
@ 2010-09-14 18:23           ` Darlan Cavalcante Moreira
  2010-09-16  3:35             ` etimecowboy
  1 sibling, 1 reply; 11+ messages in thread
From: Darlan Cavalcante Moreira @ 2010-09-14 18:23 UTC (permalink / raw)
  To: Dan Davison; +Cc: etimecowboy, emacs-orgmode


Hello Dan,

I wasn't sure if I had suggested this before or not, but now I remember
that it was in a thread about python.

I have only used org babel with python and octave and I don't know how this
would translate to other languages, but I think it makes sense in languages
that you can work with scripts. Let me elaborate.

Suppose I have the two code snippets below:
--8<---------------cut here---------------start------------->8---
#+begin_src python :results value
  from numpy import arange
  print "I don't want to see this"
  a=arange(1,10)
  a+2 # Only this as the last statement is not enough
  return a+2 # We need to add return a+2
#+end_src
--8<---------------cut here---------------end--------------->8---
--8<---------------cut here---------------start------------->8---
#+begin_src octave :results value
  disp 'I dont want to see this'
  a=1:10
  b=a+2 # Only this is not enough because ans was never set
  ans = b
#+end_src
--8<---------------cut here---------------end--------------->8---

In both cases I want to see the value of a variable after executing a
script and not what the script prints to the screen. From babel
documentation I can see that I need the "functional mode" with the header
argument :results value. However, in the python example I need to add a
"return" statement even though I didn't declare a python function in the
code (this is invalid code if I tangle it).

Also, in the octave example if the 'ans' variable was set before to some
value, babel would show it after execution, instead of the value of the
last statement as one could think.

Therefore, the suggestion is that since babel is implicitly declaring a
function (with a def in python, for example), it is more natural that it
also "write" the return statement which I could set with a ":return" header
argument and not in the language code.

The two snippets would become
--8<---------------cut here---------------start------------->8---
#+begin_src python :return b
  from numpy import arange
  print "I don't want to see this"
  a=arange(1,10)
  b=a+2
#+end_src
--8<---------------cut here---------------end--------------->8---
--8<---------------cut here---------------start------------->8---
#+begin_src octave :return b
  disp 'I dont want to see this'
  a=1:10
  b=a+2
#+end_src
--8<---------------cut here---------------end--------------->8---
where the ":results" argument would not be necessary to specify "functional
mode".

--
Darlan

At Tue, 14 Sep 2010 16:40:48 +0100,
Dan Davison wrote:
> 
> Darlan Cavalcante Moreira <darcamo@gmail.com> writes:
> 
> > Can I leave a suggestion here?
> > Maybe a header argument
> > ,----
> > | :return variableName
> > `----
> > could be interesting in org babel. This would make babel behavior more
> > uniform in all supported languages and avoid the necessity of adding code
> > "only to make babel work".
> 
> Hi Darlan,
> 
> Thanks (and sorry if you've made this suggestion previously, which I
> seem to recall). I can see that this would be particularly natural for
> matlab/octave in which (aIui) function definitions require specifying
> the name of the variable whose value is to be returned. In other
> languages which I've encountered, return values are determined by either
> "return" statements, or the value of the last statement in the function,
> or both of these mechanisms. So if we were to apply your suggestion to
> all languages, one could argue that it would permit un-natural code in
> languages other than matlab/octave. As you say, we do want things to be
> uniform across languages, but perhaps there is an argument for
> restricting your suggestion to matlab/octave?
> 
> Dan
> 
> >
> > --
> > Darlan
> >
> > At Sun, 12 Sep 2010 08:45:40 +0100 (BST),
> > etimecowboy <etimecowboy@googlemail.com> wrote:
> >> 
> >> From: Dan Davison <davison@stats.ox.ac.uk>
> >> Subject: Re: org-babel matlab example
> >> Date: Sat, 11 Sep 2010 12:23:17 -0400
> >> 
> >> > Dan Davison <davison@stats.ox.ac.uk> writes:
> >> > 
> >> >> etimecowboy <etimecowboy@googlemail.com> writes:
> >> >>
> >> >>> Hi everybody,
> >> >>>
> >> >>> I am learning to use org-babel to evaluate in-line Matlab code block,
> >> >>> but I cannot make it works when I press the "C-c C-c", nor "C-c C-v
> >> >>> e".
> >> >>
> >> >> What happens when you try C-c C-c or C-c C-v e ? There is an issue with
> >> >> matlab and octave: they return the value of the last /unassigned/
> >> >> computation
> >> > 
> >> > A better way to say this is: they return the value of the special
> >> > variable "ans". So whatever you do, at the end of the block you need to
> >> > ensure that "ans" has the value that you want returned.
> >> > 
> >> > I've updated the Worg page on Matlab and Octave:
> >> > 
> >> > http://orgmode.org/worg/org-contrib/babel/languages/ob-doc-octave-matlab.php
> >> > 
> >> > Dan
> >> > 
> >> > 
> >> >>, so simply ending the code block with a variable name "x" is
> >> >> not enough. Could you try one of the following schemes please, and let
> >> >> us know if that solves it:
> >> >>
> >> >> #+begin_src matlab :exports results
> >> >> n = [1:10];
> >> >> x = 5*n+4;
> >> >> ans = x
> >> >> #+end_src
> >> >>
> >> >> #+begin_src matlab :exports results
> >> >> n = [1:10];
> >> >> x = 5*n+4;
> >> >> x + 0
> >> >> #+end_src
> >> >>
> >> >>
> >> >>> The export of code works, but the results was not there. My in-line code is like this:
> >> >>
> >> >> There was a little typo in your original block: the keyword is
> >> >> ":exports" with an s.
> >> >>
> >> >> Dan
> >> >>
> >> >>>
> >> >>> #+begin_src matlab :export results
> >> >>> n = [1:10];
> >> >>> x = 5*n+4;
> >> >>> x
> >> >>> #+end_src
> >> >>>
> >> >>> Is there someone can provide me a working example? Thanks a lot.
> >> >>>
> >> >>>
> >> >>> -----------------------------
> >> >>>
> >> >>> etimecowboy@gmail.com
> >> >>>
> >> >>>       _.,----,._
> >> >>>     .:'        `:.
> >> >>>   .'              `.
> >> >>>  .'                `.
> >> >>>  :                  :
> >> >>>  `    .'`':'`'`/    '
> >> >>>   `.   \  |   /   ,'
> >> >>>     \   \ |  /   /
> >> >>>      `\_..,,.._/'
> >> >>>       {`'-,_`'-}
> >> >>>       {`'-,_`'-}
> >> >>>       {`'-,_`'-}
> >> >>>        `YXXXXY'
> >> >>>          ~^^~
> >> >>>
> >> >>> _______________________________________________
> >> >>> Emacs-orgmode mailing list
> >> >>> Please use `Reply All' to send replies to the list.
> >> >>> Emacs-orgmode@gnu.org
> >> >>> http://lists.gnu.org/mailman/listinfo/emacs-orgmode
> >> >>
> >> >> _______________________________________________
> >> >> Emacs-orgmode mailing list
> >> >> Please use `Reply All' to send replies to the list.
> >> >> Emacs-orgmode@gnu.org
> >> >> http://lists.gnu.org/mailman/listinfo/emacs-orgmode
> >> 
> >> Dear Dan,
> >> 
> >> I have checked the Worg page you updated and tried your example. It works! The ans variable is the secret! Thanks a lot. I suggest org should provide some examples in its user's guide, not only on the topic of Babel but also Table, Hyperlink, Picture, and etc.
> >> 
> >> -----------------------------
> >> 
> >> etimecowboy@gmail.com
> >> 
> >>       _.,----,._
> >>     .:'        `:.
> >>   .'              `.
> >>  .'                `.
> >>  :                  :
> >>  `    .'`':'`'`/    '
> >>   `.   \  |   /   ,'
> >>     \   \ |  /   /
> >>      `\_..,,.._/'
> >>       {`'-,_`'-}
> >>       {`'-,_`'-}
> >>       {`'-,_`'-}
> >>        `YXXXXY'
> >>          ~^^~
> >> 
> >> _______________________________________________
> >> Emacs-orgmode mailing list
> >> Please use `Reply All' to send replies to the list.
> >> Emacs-orgmode@gnu.org
> >> http://lists.gnu.org/mailman/listinfo/emacs-orgmode

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: org-babel matlab example
  2010-09-14 18:19           ` Achim Gratz
@ 2010-09-14 20:14             ` Achim Gratz
  0 siblings, 0 replies; 11+ messages in thread
From: Achim Gratz @ 2010-09-14 20:14 UTC (permalink / raw)
  To: emacs-orgmode

Achim Gratz <Stromeko@nexgo.de> writes:
> : {%s};ans{size(ans,1)}

That would have been too easy... if whitespace is in the wrong place,
Octave tries to parse the code block as a multi-dimensional structure
and falls onto it's own sword.  Sigh.


Achim.
-- 
+<[Q+ Matrix-12 WAVE#46+305 Neuron microQkb Andromeda XTk Blofeld]>+

Waldorf MIDI Implementation & additional documentation:
http://Synth.Stromeko.net/Downloads.html#WaldorfDocs

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Re: org-babel matlab example
  2010-09-14 18:23           ` Darlan Cavalcante Moreira
@ 2010-09-16  3:35             ` etimecowboy
  2010-09-16  6:32               ` Dan Davison
  0 siblings, 1 reply; 11+ messages in thread
From: etimecowboy @ 2010-09-16  3:35 UTC (permalink / raw)
  To: darcamo; +Cc: davison, etimecowboy, emacs-orgmode

Hi everyone,

It seems that my org used the Octave program to evaluate my Matlab code block/generate figures, not Matlab itself. I found this when comparing the exported figure by org with the figure generated by Matlab. I also found that I cannot use org-babel on an Windows PC which has Matlab installed, but not Octave.

Could someone show me how to use Matlab program to evaluate Matlab code blocks in org files in both Linux and Windows OS? Maybe it should be some settings in my .emacs file?

Thanks again.
  
-----------------------------

etimecowboy@gmail.com

      _.,----,._
    .:'        `:.
  .'              `.
 .'                `.
 :                  :
 `    .'`':'`'`/    '
  `.   \  |   /   ,'
    \   \ |  /   /
     `\_..,,.._/'
      {`'-,_`'-}
      {`'-,_`'-}
      {`'-,_`'-}
       `YXXXXY'
         ~^^~

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: org-babel matlab example
  2010-09-16  3:35             ` etimecowboy
@ 2010-09-16  6:32               ` Dan Davison
  0 siblings, 0 replies; 11+ messages in thread
From: Dan Davison @ 2010-09-16  6:32 UTC (permalink / raw)
  To: etimecowboy; +Cc: emacs-orgmode

etimecowboy <etimecowboy@googlemail.com> writes:

> Hi everyone,
>
> It seems that my org used the Octave program to evaluate my Matlab
> code block/generate figures, not Matlab itself.

Hmm, shouldn't do. Could you post your example? Have you activated both
octave and matlab? What is the value of your org-babel-load-languages?

For me C-c C-c and C-c C-v e on

#+begin_src matlab
1+1
#+end_src

result in

/bin/bash: matlab: command not found

You can confirm which language is running by using the "version"
command. Here's what I get (note I have to run matlab on a remote
computer because I don't have it on my laptop).

--8<---------------cut here---------------start------------->8---
#+begin_src octave :results output
version
#+end_src

#+results:
: ans = 3.2.4

#+begin_src matlab :dir /ddavison@tombstone.princeton.edu:/ :results output
version
#+end_src

#+results:
#+begin_example

The default version of Matlab in /usr/licensed/bin is matlab-R2009b

The following versions are available in /usr/licensed/bin:
     matlab-R2009b
   matlab-R2009a
   matlab-R2008b
Warning: No display specified.  You will not be able to display graphics on the screen.

                            < M A T L A B (R) >
                  Copyright 1984-2009 The MathWorks, Inc.
                 Version 7.9.0.529 (R2009b) 64-bit (sol64)
                              August 12, 2009

 
  To get started, type one of these: helpwin, helpdesk, or demo.
  For product information, visit www.mathworks.com.
 
>> >> 
ans =

7.9.0.529 (R2009b)

>> >> 
#+end_example
--8<---------------cut here---------------end--------------->8---



> I found this when comparing the exported figure by org with the figure generated by Matlab. I also found that I cannot use org-babel on an Windows PC which has Matlab installed, but not Octave.

In general we would appreciate any notes on problems encountered when
running Org-babel on Windows.

dan

>
> Could someone show me how to use Matlab program to evaluate Matlab code blocks in org files in both Linux and Windows OS? Maybe it should be some settings in my .emacs file?
>
> Thanks again.
>   
> -----------------------------
>
> etimecowboy@gmail.com
>
>       _.,----,._
>     .:'        `:.
>   .'              `.
>  .'                `.
>  :                  :
>  `    .'`':'`'`/    '
>   `.   \  |   /   ,'
>     \   \ |  /   /
>      `\_..,,.._/'
>       {`'-,_`'-}
>       {`'-,_`'-}
>       {`'-,_`'-}
>        `YXXXXY'
>          ~^^~
>
> _______________________________________________
> Emacs-orgmode mailing list
> Please use `Reply All' to send replies to the list.
> Emacs-orgmode@gnu.org
> http://lists.gnu.org/mailman/listinfo/emacs-orgmode

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2010-09-16  7:27 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-09-11  9:18 org-babel matlab example etimecowboy
2010-09-11 15:29 ` Dan Davison
2010-09-11 16:23   ` Dan Davison
2010-09-12  7:45     ` etimecowboy
2010-09-12 14:58       ` Darlan Cavalcante Moreira
2010-09-14 15:40         ` Dan Davison
2010-09-14 18:19           ` Achim Gratz
2010-09-14 20:14             ` Achim Gratz
2010-09-14 18:23           ` Darlan Cavalcante Moreira
2010-09-16  3:35             ` etimecowboy
2010-09-16  6:32               ` Dan Davison

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).