"pause" is not pausing the execution of script in Octave 5.1.0 in Windows 10 - octave

pause should stop the execution until something happens. But in my case where i have OCTAVE 5.1.0 on OS WINDOWS 10 is not doing its work properly. It does ignore all pause statements in script and execute the whole file.
I am running this program in my installed octave application in command window with GUI.
What may be the problem?
I have tried pause with function brackets
pause();and without function brackets pause; but still problem remains same.
%do something
plotData(X, y);
fprintf('Press enter to continue.');
pause;
%do something
plotData(X, y);
I except that script will first plot data and will stop execution till key is pressed to enable me to analyze data then after key press it would plot another plot with processed data.
But it just plot both plots in fast manner that i could not see it.

There are few bugs related to pause that have been introduced since version 5.1 and seem that recently have been fixed. It will be available in the next version. You can try alternative functions like kbhit or switch to a previous version.

Related

How can I get Octave GUI to load/read .m files correctly in editor and console?

I am taking a class on using Octave for machine learning algorithms, and as part of the assignments, they provide a series of .m files to build upon with our own code as well as to run for submission credit through the auto-grader. My problem is that the .m files load perfectly fine in a regular text editor program like Atom or Notepad, but in Octave, the files are best described as nonsense, and thus will not run in the console. If I open the files in a regular editor and copy/paste over the crazy into Octave, it seems to save it and reopen fine. But, I have close to 20 files for the first project alone, and this solution is untenable in the long run. I have a screenshot of how it's loading. Is there some setting I need to change? Uninstall/reinstall Octave? I'm new to Octave and the Octave GUI, and I'm striking out with Google for a solution. I am using version 6.2.0. Thank you for any help/advice!
screenshot of how octave is loading my .m files
Update: I responded to this in a comment below, but I tried loading it another way into Octave GUI and received the following error: ">> error: load: unable to determine file format of 'C:/Users/sophi/documents/octave/assignment_1/computeCost.m" This tracks for me because it makes sense why it would open the files in such a weird way. It's simply not sure what they are. However, I created my own simple functions from scratch to test, saved them as .m files, and was able to run them perfectly fine. I'm including one of the files below. Maybe there's a key in the formatting of the files offered by the class which is impacting Octave's ability to process it correctly?
function plotData(x, y)
%PLOTDATA Plots the data points x and y into a new figure
% PLOTDATA(x,y) plots the data points and gives the figure axes labels of
% population and profit.
figure; % open a new figure window
% ====================== YOUR CODE HERE ======================
% Instructions: .... goes on about assignment
% ============================================================
end
MOST RECENT UPDATE: The plot thickens. Yesterday, I was able to open the files I created and run them in the Octave environment, and I (wrongly) assumed they would still work today. They are doing the same stupid thing as the files included by the course. I checked inside preferences for the editor, and it says it is loading and saving them as IBM273 if that helps. Thank you for everyone has pitched in ideas. I really appreciate it!
It was 100% the encoding. I thought it was strange it was saving/loading in IBM273, so I switched it to UTF-8. Almost all the files are working now. The only ones that aren't are the ones I was trying to copy/paste yesterday to see what was going on with the load problems and the basic new problems I wrote. So I deleted everything, redownloaded, and set the default UTF-8 going forward and voila! Solved! Thanks again!
If you want to open a .m file in octave, Try this solution
It is necessary to declare a current directory before saving a file, loading a file, or running an M-file. By default, unless you edit the Octave shortcut, the current directory will be .../Octave/work. After you start Octave, change the current directory by either using the toolbar at the left-hand side of the screen, or entering the path in the bar at the top.
To open an .m file, you can use file -> open, or type
open filename

Octave pop up message

I am running Octave 4.4.1 on MacOs Catalina 10.15.7. For some weeks I have been having this message poping up when a code is running: "
It seems that [name of script] has been modified by another application. DO you want to reload it?
I click Yes each time it pops up, but when the code is running, it just keeps coming back, and sometimes Octave becomes unresponsive although the script has finished running
All I could find on the internet were either some old posts with answers about outdated Octave versions, or very complicated stuff that I would not be able to implement.
Any one knows why this happens, and what to do about it?
thanks a lot
This message is exclusive to the GUI version of Octave, and it comes up if you have a file open for editing in the Octave GUI Editor window, and the file's contents change due to a process unrelated to the Octave Editor.
E.g. you may also be editing the file on an external text editor at the same time? Or your script may be copying / generating a new file under the same name as a file that you've got open in the editor, effectively overwriting the now-out-of-date version that's still being displayed in the Octave Editor?
Octave gives you this warning to prevent you from 'saving' in your editor, and therefore undoing any changes that had been made by the external process in the meantime.

Octave: View a figure

I have the following code saved as script.
% demonstration of hold
clf;
t = linspace (0, 2*pi, 100);
plot (t, sin (t));
hold on;
plot (t, cos (t));
title ({"hold on", "2 plots shown on same graph"});
hold off;
When I execute the script within Octave, Octave's viewer shows the figure.
However, when I execute the script from the command line (Ubuntu) the viewer opens and closes alone very quickly without showing any figure.
I don't know if this issue has to do with Octave or Ubuntu. I apologize if the question is very naive.
When running and Octave script from the command line, Octave is launched to execute it, and when the script ends, Octave terminates too. This is why you see the figure windows created and immediately destroyed. There no longer is a program running to show these figure windows.
If you add a pause statement at the end of your script, Octave will wait at that statement until you press a key, then continue. So after you press the key, the script ends and Octave terminates. But while it is waiting, the figure windows will be visible.
You can use waitfor to prevent Octave from termination until the figure is closed. First you should get graphic handle of the figure. Some functions including clf , plot ,... can return a graphic handle. Then use waitfor with the handle as its argument.
h = plot(1:10);
waitfor(h);
or
h = clf;
plot(1:10);
waitfor(h);

Open a Tcl file with Wish Application

I'm running Windows 8. I have a file named "test.tcl".
If I open a shell, type "wish", then 2 windows open. In one of them, I can type Tcl code and open the file test.tcl. If I open this file, its code is executed.
If I double click on test.tcl to open the file with "Wish Application", then 1 blank window open, and nothing happens.
Do you know why please?
On Windows, Wish is built as a GUI-only application; it has no real standard output available. Tk fakes one for you though; just put this in your script to show the fake console:
console show
The fake console shows up by default when you launch without a script file, but launching with a script file doesn't show it (so your script file can implement an application, of course).
This can catch people out when they produce a lot of output on stdout. Tk may well be keeping it all faithfully just in case the code does console show later on, though it looks and smells a lot like a memory leak if you're not prepared for it…

Difference between async and sync in octave?

I was having issues with the editor in octave and posted an question before: Octave output buffer completely messed up on OS X. How to fix?
The way how I fixed the question is using edit mode sync instead of the default async. However, I don't really understand what's the difference between async and sync here? And why when using async the keyboard was sending signals to both octave and the editor so that the output buffer gets messed up? If possible, can we use async mode for macbook? (Since everything works fine on my linux computer)
According to the help text of `edit()':
[...] async mode (editor is started in the background and Octave continues) or sync mode (Octave waits until the editor exits). [...] (see also "system").
It basically defines what happens after starting the other process (emacs in your case). Think how edit() was designed to be used. You are at the Octave prompt and use it to open a function file in your text editor. You make changes to the file while still using the Octave prompt. That's async mode.
However, your text editor does not a have a GUI. When you start emacs, you use it on the same terminal window where you called it from. Because you have it set to async, you end up with both emacs and Octave interactive in the same terminal. Set it to sync means that until you exit emacs, Octave is just waiting so it doesn't mess up with what's being displayed.
You can:
use a text editor with a GUI;
change your EDITOR command to open a new terminal, and start your CLI emacs there. For example, if you are using gnome-terminal, you can set it to gnome-terminal -e emacs %s;
change mode to sync.