1

When using the Octave input function, e.g.

a = input('Value of a: ');

and entering, say, 5, this of course sets a=5. When I press the up arrow to access the most recent command history, instead of going back to 5, goes back to defining a with the input function again (and, unsurprisingly, the 5 does not show up in the Octave GUI command history window). Is there a setting, action to take, or alternative method to use to access input function key-presses as well? I recall that these key-presses were kept in command history and accessible with the arrow keys by default in Matlab, at least in the versions from the early 2010's.

This is a simple example of course, but I have a larger script with multiple input functions (some of them requiring fairly large strings), and since I'm only using the input function to interact with the script while it's running, I effectively have no access to any command history at all during this process. Thanks for any advice you can offer.

smcmi
  • 106
  • 8
  • 1
    why not save the results on a file/variable, and instead of pressing "up" load up that variable – Ander Biguri May 05 '21 at 13:58
  • @AnderBiguri, thank you for the suggestion. I do like your idea when working within a single invocation of my script. If I exit the script, I leave the work space, and have to start over when I invoke it again, and this is where the up/down arrow behavior would be convenient, but this is progress, and I appreciate it. – smcmi May 05 '21 at 14:31
  • 1
    you could use the `diary` command to log your session, and recover the inputted values. If your end goal is to be able to 'up-arrow' back to them, you could process your resulting diary file to isolate only the lines where you provided input (should be easy given the prompt), comment them, and then try to run them in turn. This will at least guarantee 'commented' versions of what you want to pass as input will exist (and all you have to do then is uncomment those lines). Having said that, this is totally a hack, and you shouldn't be relying on console input too much in any serious application – Tasos Papastylianou May 05 '21 at 21:32
  • @TasosPapastylianou, thank you for the suggestions. I'll look into this. My script takes a product design, and there are options (over 40 and counting) to calculate various quantities, make adjustments, and create documents used in manufacturing. You've already helped me with this on several fronts, and I appreciate it. If it's not a good idea to rely on console input (and this is definitely a serious application), what is a viable alternative to interact with the script? Thanks again. – smcmi May 06 '21 at 13:55
  • To clarify, are you able to change this script to change the way it works? Or are you stuck with a predefined script and only able to interact with it, and you'd like a way to automate "inputting" stuff? If it's the latter, you might be able to use your script with something like [expect](https://likegeeks.com/expect-command/) – Tasos Papastylianou May 06 '21 at 15:30
  • not that this is exactly a compatibility issue, more of a user experience issue, but noting that at least in Matlab 2021a the command history does recall all inputs including to an input command as mentioned in the OP. Octave does not retain such inputs. You could file this as a feature request 'bug' over at https://bugs.octave.org , but it might not get high priority as some overall interpreter rework is currently being done. – Nick J May 06 '21 at 18:25
  • @TasosPapastylianou, I'm writing all the code in its entirety, so I have complete control. A blessing and a curse, as they say! So if you can tell me a better way to interact with the script without using (or at least limiting the use of) the `input` function, please do let me know. I'll research the `expect` command in the meantime anyway for my own education at least. – smcmi May 07 '21 at 12:39
  • @NickJ, I'll give it a shot, it can't hurt to try. – smcmi May 07 '21 at 12:40
  • 1
    @smcmi for me the sanest way would be to create a configuration file, where you specify all your inputs. The main program then simply reads the inputs from the configuration file. This has the added benefit that it allows you to keep a record of configuration files (i.e. inputs) linked to particular outcomes. This config file should be whatever suits your needs best: it may be text-based, or it may be a simple .mat file. – Tasos Papastylianou May 07 '21 at 13:54

0 Answers0