I was trying to the following line in octave as part of a GUI plot program.
if nargin == 0
warning off
fig = openfig(mfilename,'reuse');
warning on
But I'm getting the following error
error: 'openfig' undefined near line xx
Is this function not available in octave? How can I get it?
I tried posting this as a comment but it messed up the formatting, so posting as an answer instead, though its really more of a comment.
I can't replicate your error. If I run the following script to save 'Unitled.fig':
x = linspace (0, 2*pi, 200);
y = sin(x);
plot(x,y);
savefig(gcf);
and then run:
n = 0;
mfilename = 'Untitled'
if n == 0
warning off
fig = openfig(mfilename,'reuse');
warning on
endif
it works fine on my machine using Octave 5.2.0, though the 'reuse' option isn't mentioned in the Octave manual. Maybe the file you are trying to open is an incompatible format? Was it originally saved using Matlab?
Related
I have a very short script that I'm running in Octave and I want to read a user specified text file. It works on my 64-bit laptop, but not on my 32-bit one. The Octave version is 3.2.2.
plotinfra.m
filename=uiputfile
data=load(filename);
plot(data(:,1),data(:,2));
On my other laptop, this brings up a filesystem menu where I can choose the specific file to load. On this laptop, I see this error message instead:
error: uiputfile undefined near line 1 column 19 error: called from: error: plotinfra.m at line 1, column 17
If I hardcode filename with a path it works. I also tried using uigetfile and that did not work either.
Version 3.2.2 of Octave was released in 2009. When I enter edit uiputfile in Octave, at the top of the file I see the line:
## Copyright (C) 2010-2019 Kai Habel
Thus, it seems that this function was created after your release of Octave. This is the reason you get a "uiputfile undefined" error message.
You will have to upgrade your version of Octave to use this function.
I'm using Ubuntu 18.04 64Bit Linux Octave 4.2.2 see if this works for you. It will store the filename in the variable file_name and the path location in the variable path_dir
% create your dataset (exampledata)
x = (-1:0.1:1);
y = sin(x);
data = zeros(length(x),2);
data(:,1) = x;
data(:,2) = y;
% save data to file (your textfile)
save('-ascii','data2.txt','data');
%load textfile
%data2 = load('data2.txt'); %hard coded
[file_name,path_dir] = uigetfile('*.txt'); %pops up uibox choose data2.txt
data2 = load(strcat(path_dir,file_name)); %loads the file and the data
%plot data
plot(data2(:,1),data2(:,2));
I am using log2 function in Octave to calculate log2 values of a simple array.
>> x = [1:5]
x =
1 2 3 4 5
>> log2(x)
error: invalid use of script D:\All_Data\my_data\backup3\backup3\tech\DSP\log2.m in index expression
I am not sure why Octave is bailing out with error in this case ...
You probably have a script that is called log2.m in your running directory, which prevents octave from calling its own log2 function.
I assume that is the case because D:\All_Data\my_data\backup3\backup3\tech\DSP\log2.m
doesn't look like a path where standard octave library functions would be installed.
I recommend changing the name of the script in your running directory.
I'm using the Octave kernel in a Jupyter notebook. When I try to load a matrix from a file using the dlmread function, the whole data is printed. I tried assigning the result to a variable immediately, but no luck. This is troublesome because the matrix is quite large (~17*500) so it takes a while to print.
I just want to load my data without having all of it printed.
I guess you don't have a ; at the end of your dlmread command. See the manual:
Ending a command with a semicolon tells Octave not to print the result of the command
See this example:
>> a = 4 + 5
a = 9
>> b = 5 + 6;
>>
I'm beginning with octave. I've created a file called squareThisNumber.m in My Documents with the following code:
function y = squareThisNumber(x)
y = x^2;
I set the directory to look at My Documents with
cd 'C:\Users\XXXX\My Documents'
I type "squareThisNumber(3)" into octave, and all I'm getting is "Error: 'squareThisNumber' undefined near line 3 column 1." What am I doing wrong?
EDIT:
When I type ls into octave, I get "error: ls: command exited abnormally with status 127". Did I not install Octave correctly?
This behavior sure does seem like there's a problem with octave's current working directory. Does the command dir or pwd also have the same problem?
But you might be able to ignore all of that by
addpath("C:\Users\XXXX\My Documents");
Did you place the end keyword at the end? Code example below works perfectly for me
https://saturnapi.com/fullstack/function-example
% Welcome to Saturn's MATLAB-Octave API.
% Delete the sample code below these comments and write your own!
function y = squareThisNumber(x)
y = x^2;
end
squareThisNumber(9)
I have big problem(s) with configuration of SciTE in context of Python 3. I do not know if details have any meaning, so:
[DETAILS]
I downloaded and executed gen_python_3_api.py.
I created folder "api" in usr/share/scite and copy-pasted there python3.api
I edited SciTEUser.properties as written in documentation of gen_python_3_api.py. It did not help a bit, so:
I used more general way found on website of SciTE. I edited python.properties and added a line:
api.$(file.patterns.py)=$(SciteDefaultHome)\api\python.api.
Still no effect.
I just edited another line of python.properties:
if PLAT_GTK
command.go.*.py=python3 -u "$(FileNameExt)"
It finally worked (or I though so).
[/DETAILS]
Now I want to run simple Fibbonaci program that worked well with IDLE.
def Fib(n):
a = 0
b = 1
FibL = []
for i in range (n):
FibL.append(a)
z = a
a = b
b = b+z
return FibL
n = int(input("Number? "))
print(Fib(n))
And I get:
>python3 -u "test.py"
Number? Traceback (most recent call last):
File "test.py", line 38, in <module>
n = int(input("Number? "))
EOFError: EOF when reading a line
>Exit code: 1
I am completely confused. Do somebody know why this things happen and how to fix it?
First of all, the generation of api is for editing only, not running your code.
Resolve the ambiguity with versions by adding full path to command lines (Hope, you do so in the 5th point of the question details)
The problem is in the line:
n = int(input("Number? "))
Here you want input from user, i.e. interactive running, but editor runs commands inside its process and can output simply.
Change your code by adding variable instead of the input command
n=5
or use parameters http://www.scintilla.org/SciTEDoc.html#property-if
Good luck!