|
From: | John Helly |
Subject: | Re: Newbie problem running *.m files on Octave 3.4.2 on Snow Leopard |
Date: | Sat, 30 Jul 2011 16:32:27 -1000 |
Thanks again. I'm trying to run this sample code I found just to see how/if Octave works before giving it something more complex that already runs in Matlab. The documentation suggests that all that is necessary is to invoke Octave with a file as an argument and it will run the file and exit. What happens is that the bottom window pops up as you surmized; no files are created. I added 'pause' at the end of the file and it had no effect. =========== example code begins here. %Using Matlab or Octave for a simple bike example %from class notes %7Jan2009 -mrc %Set up some definitions and conversions theta = 5.74; % degrees hp = 0.2; % rider power, (hp) mass = 100; % mass bike+rider (kg) rwheel = 0.33; % wheel radius (m) rpm = 90; % crank speed (rpm) %Convert to consistent units watts = hp*745; omegacrank = rpm*2*pi/60; % omega of crank (rad/s) %With no losses, output power = input power %And output power = force * velocity, where force = mgsin(theta) Fbike = mass*9.8*sin(pi*theta/180); Vbike = watts/Fbike; omegawheel = Vbike/rwheel; sratio = omegacrank/omegawheel %I feel like plotting something... %Let's define things with some arrays %a range of human powers from wimpy to mahnly powers = [0.1, 0.125, 0.15, 0.175, 0.2]; watts = powers*745; %now these are arrays Vbike = watts/Fbike omegawheel = Vbike/rwheel; %omegacrank is still a scalar. So use the "./" syntax %and it divides each element one by one sratio = omegacrank./omegawheel %plot with separate left, right vertical axes for 2 curves clf % clear figure if there was one ax = plotyy(powers,Vbike,powers,sratio) xlabel ('power (hp)'); ylabel (ax(1), 'speed (m/s)'); ylabel (ax(2), 'crank-wheel ratio'); ===================================== example code ends here =============== Cheers. -------------- John Helly, University of California, San Diego / San Diego Supercomputer Center / Scripps Institution of Oceanography / 760 840 8660 mobile / stonesteps7 (Skype) / stonesteps7 (iChat) / http://www.sdsc.edu/~hellyj On Jul 30, 2011, at 4:24 PM, Jordi Gutiérrez Hermoso wrote: 2011/7/30 John Helly <address@hidden>: On Jul 30, 2011, at 3:56 PM, Jordi Gutiérrez Hermoso wrote: On 30 July 2011 20:41, John Helly <address@hidden> wrote: I've put /Applications/Octave.app/Contents/MacOS in my path and aliased octave='Octave' and I can start 'octave' from the Terminal command-line but whether I give it a *.m filename or not it always opens up an interactive session. What did you type, what was the exact output? I find it odd that if you type "octave -q foo.m", you end up in an interactive session, if this is indeed what you're doing. Thanks very much. I didn't know about the -q switch but it doesn't seem to have any effect. That is precisely its effect, to suppress output ("[q]uiet"), i.e. to not show the startup message about the license, etc. Here's a screen grab of what happens. The upper window is the command-line invocation and the lower window is the result. Nothing else happens. Why do you think the lower window is the result? Did that lower window pop up when you type "octave -q bike_example.m"? Did you check that this did not produce any output, e.g. an image or data file in the current directory? Is bike_example.m perhaps supposed to display an image on screen? If so, you may need to add "pause" at the end of the file. If bike_example.m is only a function file, not a script file, executing it this way accomplishes nothing but to define that function and immediately exit, but not to execute the code in the function. If this is the case, try octave -q --eval "bike_example(some, parameters, 1, 2, 3)" instead. I've also tried building octave-3.4.2 but it fails with a flex problem in builtins.cc that seems to be an old problem and I can't figure that out. Can you say what the problem is? Just post the error messages you see. builtins.cc:25096:2: error: #error lex.l requires flex version 2.5.4 or later Oh, yes. Apple ships ancient versions of GNU software because they refuse to ship anything under the GPLv3 (which, btw, Octave uses). I believe it's possible to still easily obtain newer versions through 3rd-party channels not restricted by Apple, but I am not sure how. However, I'm confused. I thought you only needed flex if you needed to rebuild a tarball or modify the parser. I hope someone else can comment on why you're seeing this; it shouldn't happen from a tarball. I then tried building from the source gotten from hg clone http://www.octave.org/hg/octave but that doesn't seem to have configure bundled with it. These are developer sources and not recommended unless you want to help with Octave's development itself. You have to build your own configure script using GNU autotools if you want to work from the hg sources. If you have installed autotools (and git, and probably many many other things), do "./autogen.sh" to produce a configure script. And I will run the autogen to see if that helps. Unlikely. If you're having trouble building from a tarball, building from the developers' sources is going to be even more trouble. HTH, - Jordi G. H. |
[Prev in Thread] | Current Thread | [Next in Thread] |