Octave: View a figure - octave

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

Related

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

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.

Running a Tcl script opens a blank window

I have a tcl script that I wrote called perm.tcl I'm trying to run this script on a windows machine.
package require Tk
proc invert list {
set length [llength $list]
return $length
}
invert {1 2 3 4}
Whenever i try to run this code in a command prompt using
tclsh perm.tcl
a blank activetcl window opens titled "perm" with no text or anything. In this case it should simply output the number 4 but im getting just a small greyed out window. I know this procedure works because when i painstakingly write it out in the tclsh command prompt i get the desired result of 4. Please help
It is because you are importing the Tk package. When you do that, it automatically creates a window. If you don't want any windows, don't import Tk.

Command to send signals to waveform in SimVision

Is there a (Tcl-)command I can use to send signals to waveform in SimVision?
Of course You can rightclick them and then select "Send to WaveForm Window", but to do that each time you start a simulation will be a pain.
In Modelsim you can easily use "add wave" in a dofile (tcl file), but strange if there would be no way to do this with ncsim...
When you have your waveform window set up the way you like (with all desired signals), you can go to File -> Save Command Script . This will save your window setup as a tcl file. You can look in there to see what the tcl commands are if you are interested in doing it manually.
To restore the waveform window next time, simply go to File -> Source Command Script and select the file you had saved previously.
Note: I'm using SimVision 12.10
a minimal working example I've come up with:
window new WaveWindow -name "Waveform"
waveform using {Waveform}
waveform add -signals tb_foo_u.module_bar_u.signal_xyz
You can type that in the SimVision console (if you're using irun in GUI mode). Tested in 15.20. Those are simulator-specific commands.
If you want it to be done automatically # irun startup (using .tcl file), examine the results of running commands from the other answer, then tailor it to your needs.
For the full, verbose description of waveform instruction, refer to the documentation provided with the simulator under SimVision Tcl Commands / waveform.

Octave input from keyboard not working in a script

I'm writing a script in octave that needs an input from keyboard in order to select a function to be used further. I've read the documentation and understood that
ans = input("choose...")
should wait for the for the input and store it in the ans variable. When I use it in the octave terminal it works just fine, but it doesn't when I insert it in my script : It shows the message "choose..." but it doesn't wait.
I don't get it, What I am missing.
Thanks,

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.