FAQ Database Discussion Community


Getting the error “ `butter' undefined” in Octave. How to fix it?

matlab,octave
When I write this line in Octave: [b,a] = butter (5,0.2); I get the error: error: `butter' undefined near line 1 column 10 How can I get rid of it? Thanks....

How to do bitwise operation decently?

matlab,bit-manipulation,octave
I'm doing analysis on binary data. Suppose I have two uint8 data values: a = uint8(0xAB); b = uint8(0xCD); I want to take the lower two bits from a, and whole content from b, to make a 10 bit value. In C-style, it should be like: (a[2:1] << 8) |...

Octave: how can these FOR loops be vectorized?

matlab,octave,vectorization
I am writing an Octave script to calculate the price of an European option. The first part uses Monte Carlo to simulate the underlying asset price over n number of time periods. This is repeated nIter number of times. Octave makes it very easy to setup initial matrices. But I...

can not use help in octave 3.8.1 on mac

osx,octave
when i enter: >> help help i get error message: error: unable to open /usr/local/Cellar/octave/3.8.1_1/share/octave/3.8.1/etc/macros.texi for reading error: called from: error: /usr/local/Cellar/octave/3.8.1_1/share/octave/3.8.1/m/help/__makeinfo__.m at line 103, column 5 error: /usr/local/Cellar/octave/3.8.1_1/share/octave/3.8.1/m/help/help.m at line 99, column 22 How could i solve it? I'm using this on MacOS 10.10.2....

Using variables from one Octave function file in another

scope,octave
Say I have two Octave function files in the same load path: file1.m and file2.m. file1: function [variable] = file1() variable = 1; endfunction file2: function file2() variable2 = variable*2; endfunction How can I make it so that I can use variable in file2? I have tried many things, such...

Create an increasing integer alternating sequence in MATLAB / Octave

matlab,octave,numerical-methods,numerical
I'm trying to find a way to create a number pattern like the one below 0,1,-2,3,-4,5.... Please note: it needs to go to 200000, but I will be splitting them up into groups of 2000. I found a formula that looks like it would work on http://oeis.org/A181983, but when I...

Multipling row and column vector using .* operation

matrix,octave,matrix-multiplication,broadcasting
a = 1 2 3 b = 1 2 3 a.*b ans = 1 2 3 2 4 6 3 6 9 I used the .* operator to multiply a row vector and a column vector in Octave to see the results. I dont understand how the answer is obtained....

Where to find detailed doc on functions?

octave
To find doc on function zeros right click on function within Octave UI and select Documentation. This give some information on the function but does not detail the meaning of parameters. e.g this code : z = zeros(2, 2); creates 2x2 Matrix of zeros. But what does this invocation mean...

Octave code to plot labeled data

matlab,plot,octave,svm
Good afternoon, guys. I'm learning SVM and try to finish an exercise at openclassroom.stanford.edu. My question is: What is the Octave/Matlab code to plot as follows If I have a set of 2D feature points {(x_11, x_12), (x_21, x_22), ..., (x_i1, x_i2)}, and the corresponding labels set is {1, -1,...

Octave plot different colour for every point

plot,octave
I am having a specific problem. Firstly I am using octave. I have a dataset where every row is of the following format: datarow = [ x, y, z, colourIndex]; The length of the dataset is irrelevant, but suppose it is 10. I want to be able to plot the...

What does the value NaN4505e-001 mean in Octave/matlab? [closed]

matlab,octave
What does the value NaN4505e-001 mean in Octave/matlab? The full output line is Iteration 250 | Cost: NaN9784e-001 The corresponding statement in the library function is fprintf('%s %4i | Cost: %4.6e\r', S, i, f1); So, my question is how can a %4.6e return this value NaN4505e-001?...

Color points on a plot according to a vector in Octave

matlab,plot,octave
I want to plot multiple 2d-points which are stored in a N-by-3 matrix. The first 2 columns define the x and y coordinate. The 3rd column defines the index of the color to be used for a single point and refers to an a list of color codes like this...

Switching values to plot using keyboard input

matlab,octave,matlab-figure
I have sets of data in a matrix. I want to plot on set and then use a keyboard input to move to another one. It's simply possible this way: for t=1:N plot(data(:,t)) pause end but I want to move forward and backward in time t (e.g. using arrows). OK,...

How does this Matlab/Octave code create a Boolean matrix from a vector?

arrays,matlab,matrix,octave,linear-algebra
The first line of code creates some vector with "discrete labels", and the second line of code creates a sparse matrix with ones at the index that the label represents. "eye" creates an identity matrix, but then even if the vector "a" is much longer, this effect of creating a...

Transpose of a row vector in Octave causing problems with string escape character

sublimetext2,octave
In Sublime, I'm trying to take the transpose of a row vector in an Octave file as such: y = [4, 5, 6]; y_transpose = y'; But whenever I try to run this in Octave, it acts as if introduction of the transpose operator (the ') is the beginning of...

Fitnet function analogue in Octave

matlab,neural-network,octave
Octave is considered as open source implementation of MATLAB. In MATLAB there is a function fitnet. Does anybody know a corresponding function in Octave? P.S.: I have also installed in my octave edition an Octave´s neural network package. Or, maybe, does somebody know about some other package, which has this...

Matlab P file opening in Octave

matlab,octave
I use Octave and have a Matlab made P file (protected function file). How can I open it, use it with Octave? Are there any method to convert it maybe or get content from it?

What's the easiest way to extract contour of segmented image?

image,octave,contour
Let's say i have an image like that one: After some quick messing around, i got a binary image of the axe, like that: What is the easiest/fastest way to get the contour of that image using GNU/Octave?...

How to calculate the size of a vector of this form?

arrays,matlab,octave
In Matlab, it's easy to define a vector this way: x = a:b:c, where a,b,c are real numbers, a < c and b <= c - a. My problem is that I'm having troubles trying to define a formula to calculate the number of elements in x. I know that...

how to count the row which match a combined condition?

octave
For example, I have matrix m = 1 0 1 0 1 1; 0 1 0 1 0 1; 1 0 1 0 1 1; 0 1 0 1 0 1 I want count the number of row which first element m(i, 1) = 1 and third element m(i,3) =...

Reset ColorOrder index for plotting in Matlab / Octave

matlab,plot,octave
I have matrices x1, x2, ... containing variable number of row vectors. I do successive plots figure hold all % or hold on plot(x1') plot(x2') plot(x3') Matlab or octave normally iterates through ColorOrder and plot each line in different color. But I want each plot command to start again with...

Mkfifo in GNU Octave

octave
I have yet to find a complete example for using the mkfifo() function online. I am able to make the fifo like this: mkfifo("file",777) But when I fopen() this file, Octave just hangs. What is the proper way to create, queue, and dequeue bytes from a mkfifo object? I would...

Find a circle cirle tangent using an iterative, numerical, method

matlab,geometry,octave,numerical-methods
Given: centers and radii of two circles My problem is that I cannot figure out how to use a numerical method to find a circle circle tangent. I have search all over the net and nowhere do I find any clues. Using http://mathworld.wolfram.com/Circle-CircleTangents.html I would have some idea of...

How to find coefficients for a possible exponential approximation

matlab,octave,curve-fitting,data-fitting
I have data like this: y = [0.001 0.0042222222 0.0074444444 0.0106666667 0.0138888889 0.0171111111 0.0203333333 0.0235555556 0.0267777778 0.03] and x = [3.52E-06 9.72E-05 0.0002822918 0.0004929136 0.0006759156 0.0008199029 0.0009092797 0.0009458332 0.0009749509 0.0009892005] and I want y to be a function of x with y = a(0.01 − b*n^−cx). What is the best...

Finding the shortest repetitive pattern in a string

regex,matlab,pattern-matching,octave,maple
I was wondering if there was a way to do pattern matching in Octave / matlab? I know Maple 10 has commands to do this but not sure what I need to do in Octave / Matlab. So if a number was 12341234123412341234 the pattern match would be 1234. I'm...

Plotting in matlab / octave by grouping numbers into a range

matlab,plot,gnuplot,octave
I'm trying to have the data be the x-axis and the y-axis be the amount of values grouped by 10. See Plot below as example I tried using bar(x) but I'm not sure how you get the numbers in the correct categories for plotting. example: if the data is x=1,5.3,9,10.5,12,13,15.2,25,191,192.4...

Does Octave support enumeration like Matlab?

matlab,octave,enumeration
Does Octave support enumeration like Matlab? I haven't found any info about it. We can create an enumeration class by adding an enumeration block to a class definition. For example, the WeekDays class enumerates a set of days of the week (from Matlab doc). %file WeekDays.m classdef WeekDays enumeration Monday,...

Octave error: no default value for argument 1 while calling function

matlab,octave
I need to find normalized value for each value by column. So I have such function: function [X_norm, mu, sigma] = featureNormalize(X) X_norm = X; mu = zeros(1, size(X, 2)); sigma = zeros(1, size(X, 2)); for x = 1:size(X, 1) mu(1,x) = mean(:, x) sigma(1,x) = std(:, x) for y...

How imwrite in loop write many different images in Octave/Matlab

matlab,loops,image-processing,octave
In loop when I generate images I use this string imwrite(IWindow, gray(256), 'plane', 'tif'); to write the image of this iteration. In this loop I have z iterator....

Intersect operations with fractional values in MATLAB

matlab,octave
I want to intersect some fractional values: frac_value = intersect (find(xmin > 0) , find(xmin < 1)) where xmin is a large vector of fractional values. I have printed xmin values till 0.16f, where some of them are showing values 0.0000000000000000, but frac_value returning it's position. I have no idea...

Creating an array of matrix as an input of function in Matlab

arrays,matlab,function,matrix,octave
I would like to create several matrices to represent Hilbert matrices of different orders. The matrix will then be called by a function. However, error messages appeared saying that the function(GE) is not defined. But if I put the function on top of the for loop, another similar message appeared...

Syntax Error in Octave plotting

plot,fft,octave
I got the following syntax error while I want to plot values: syntax error >>> plot(freq1, abs(fft1/max(fft1)),xlabel('f(Hz)'), ylabel('Amplitude I(f)'); ^ My definitions are as follows: a=x+y+z; % a is a sinus mixture of different curves/functions n1 = fa/0.05; % N is 50 ms fft1=fft(a,n1); freq1 = [0:deltaF1:fa-fft1]; plot(freq1, abs(fft1/max(fft1)),xlabel('f(Hz)'), ylabel('Amplitude...

How to execute multi-line Maxima code from Octave / Matlab

matlab,octave,maxima
I can execute Maxima code from Octave like this and it works: mm=maxima("diff(a*x^3-b*x^2+x+d,x,1)") but how can I execute multi line commands? Example code below that works in Maxima kill(all)$ numer:true$ ratprint:false$ angle_in_bits:3779$ total_fs:18136$ s:solve(angle_deg=(angle_in_bits/total_fs*360),angle_deg)$ round(s); [round(angle_deg)=75] When I try the code below in Octave I get syntax errors mm=maxima("kill(all)$ numer:true$...

To categorize jet colormap by pixels of some colors

matlab,octave,colormap
Data I want to categorize it by counting the following pixels through HSV (Hue-Saturation-Lightness) dark blue blue green yellow red To show RGB channels (source) without HSV x = linspace(0,1, size(Map)(1)); figure(Fignr) lw = 4; plot( x, Map(:,1),'color',[1,0,0],'linewidth',lw, x, Map(:,2),'color',[0,1,0],'linewidth',lw, x, Map(:,3),'color',[0,0,1],'linewidth',lw, x, mean(Map,2),'color',[0.7,0.7,0.7],'o') xlabel 'fraction' ylabel 'intensity' end where...

How to perform element wise addition to a particular row in Octave?

matrix,octave,matrix-multiplication
I've a two matrices A = [0 0 0; 0 0 0; 0 0 0] and B = [2 3 4;] How will I get A = [0 0 0; 2 3 4; 0 0 0]...

for loop logic in matlab / octave incrementing

matlab,for-loop,octave
I have two lines where ii should increment 1:12 1 2 3 4 5 6 7 8 9 10 11 12 for ii=1:6 ii %line1 ii+1 %line2 end Instead I get ii 1 2 2 3 3 4 4 5 5 6 6 7 Ps: I need to use two...

Matrix manipulation in Octave

matrix,octave
I want to map a mX1 matrix X into mXp matrix Y where each row in the new matrix is as follows: Y = [ X X.^2 X.^3 ..... X.^p] I tried to use the following code: Y = zeros(m, p); for i=1:m Y(i,:) = X(i); for c=2:p Y(i,:) =...

What is an NDArray in octave

arrays,matrix,multidimensional-array,types,octave
What is an NDArray in octave? What does the "ND" in NDArray stand for? Seemed like a case for Google, but I could not find any good descriptions.

Manage font type and size of text on Matlab plot

image,matlab,octave
I have achieved to plot a 28x28 grayscale image on Matlab and also to insert a number at a particular location of the figure, but how can I increase the size of the font, change its color or its type (e.g. verdana). % myImage is a 28x28 matrix with values...

How to overload clear

matlab,octave,built-in
Overloading clear() with a function is easy. But how to access the workspace of the upstream function (from which clear was called) to clear the workspace? builtin('clear') will only clear the workspace of the overloaded function. function ret = someFun(a,b) ret = a + b; clear ret = 1; end...

trouble with my octave function

matlab,function,octave
I think I am missing something very basic here function F = non_iter(x,kc,kw) F = [x(6)*x(4)*kc-3*x(2); x(2)*x(5)-kw*x(6)*x(3); x(2)+x(6)-1; x(1) -7.52; x(6)+2*x(4)+2*x(2)+x(3)-4; x(3)+x(5)-8]; end when I call this, like fu = non_iter(x,kc,kw) It says vertical dimension mismatch (3x1 vs 1x2) x is supposed to be a row vector of length 6...

Error when using xlswrite in Octave

excel,octave,export-to-excel
I am trying to write a cell array to an Excel spreadsheet in Octave using the xlswrite from the io package in Octave (3.8.0, io 2.0.2 loaded, using Windows 7 64 bit). The cell array looks like this: >> pump_backlash(1:3,:) ans = { [1,1] = Machine # [2,1] = Machine_01...

Matlab: how to fit time series with a funcion of a certain type

matlab,math,octave
I'm having a time series and need to aproximate it with some function which is easy to calculate. It looks like the row is something like (a*x*x + b*x + c) / (d*x + e) Is there a way to find the coeficients automatically (with Matlab or whatever) the so...

Using octave built-in function in C

c++,c,octave,built-in
I am told to compile this program using C in octave. I have succeeded in compiling a simple C program before using Octave, but for this one, I have tried and I have no idea how to compile it in C even though I have tried to change some of...

Composite trapezoid rule not running in Octave

octave,numerical-methods,numerical-integration
I have the following code in Octave for implementing the composite trapezoid rule and for some reason the function only stalls whenever I execute it in Octave on f = @(x) x^2, a = 0, b = 4, TOL = 10^-6. Whenever I call trapezoid(f, a, b, TOL), nothing happens...

How not to repeat values in array using matlab / octave

arrays,matlab,octave
Thanks goes out to Shai for getting my code to be much more efficient. The link to the original thread is here. Original Thread How can I have a loop check and stop if a number in the "array_all" array has been repeated from the "x" array. Example: Here's the...

Octave/Matlab - Are all elements in the vector the same? [duplicate]

matlab,octave
This question already has an answer here: How to check if all of the elements in an array are the same, in matlab? 3 answers I need a way to test if all elements in a vector are the same In my script, I start with an empty vector...

Octave: Kmeans clustering not working on an image matrix

matlab,image-processing,machine-learning,octave,k-means
I have tried the following code. img=imread("test1.jpg"); gimg=rgb2gray(img); imshow(gimg); bw = gimg < 255; L = bwlabel(bw); imshow(label2rgb(L, @jet, [.7 .7 .7])) s = regionprops(L, 'PixelIdxList', 'PixelList'); s(1).PixelList(1:4, :) idx = s(1).PixelIdxList; sum_region1 = sum(gimg(idx)); x = s(1).PixelList(:, 1); y = s(1).PixelList(:, 2); xbar = sum(x .* double(gimg(idx))) / sum_region1...

interpn returns diagonal instead of interpolated matrix

octave
Using interpn in octave I get an unexpected result: Data=rand(10,3); interpn(Data,[1,2,3],1:size(Data,2)); I would expect the first three rows of Data but instead it returns a single row vector containing [Data(1,1),Data(2,2,),Data(3,3)]. Any explanation for this behaviour I missed in the documentation or is this a bug?...

Ways around pinv([inf])=NaN in Octave/Matlab

matlab,octave,matrix-inverse
I am using Octave 3.8.1, a Matlab-like program. I'd like to generalize 1/x to the case where x may be a scalar or a matrix. Replacing 1/x with inv(x) or pinv(x) works for most x, except: octave:1> 1/inf ans = 0 octave:2> pinv([inf]) ans = NaN octave:3> inv([inf]) warning: inverse:...

Change the color of a pixel in an imagesc plot without repainting everything in Matlab/Octave

matlab,octave
I have a for-loop where I would like to paint at every step a new pixel in an imagesc plot. I am currently repainting the whole figure but the figure is blinkering and I know it is not the proper way to do so. Can anyone help to find the...

Difference between simplex method and revised simplex method in GLPK solver

matlab,octave,linear-programming,glpk
I am trying to solve an LP minimization problem with glpk solver in octave for large data. my constraint matrix is having 1000 or more rows. I am confused about using that lpsolver=1 option of glpk. I do not the difference of using that or not. Will I get the...

Attempt to get numbers instead of NaN values when printing

printing,octave,binomial-cdf
I've a simple program with a for loop where i calculate some value that I print to the screen, but only the first value is printed, the rest is just NaN values. Is there any way to fix this? I suppose the numbers might have a lot of decimals thus...

'No primal feasible solution' error in GLPK

matlab,octave,linear-programming,glpk
I am solving a minimization problem to cover 3d points with axis parallel lines with GLPK. initially I set lb as 0 and ub as 1. then after getting the GLPK result, I make the first fractional variable value 0 and then change the lb and ub values as: i)...

Failed to plot simple graph in Octave

matlab,graph,plot,octave
I want to draw a line on a graph to find the intersection point with another line. However, there's no response after I executed the script below. May I know what is the problem and how can I solve it? x=1:2^20; y2=2^24; plot(x,y2); Thanks!...

source code of GNU Octave function: mldivide

octave,linear-algebra
Where can I find source code of mldivide of GNU Octave? Is it implemented as C++ code or is it m-file? Typing which mldivide in GNU Octave command line returns mldivide is a built-in function. I searched but I couldn't find the source code.

DC part isolation

matlab,signal-processing,octave
I have a signal consisting of fast oscillating AC part and slowly varying DC part. I need to calcuate its DC part (and envelope, but that's not important now). I could use the STFT, filter and transform it back, but it's a little inefficient cause I am not looking for...

Creating a number pattern based on the length of an array

matlab,math,matrix,octave
Creating a number pattern based on the length of array, the example is small just showing what it would look like if the array had a size of 5,6 or 7. (the actually length of arrays will be around 400,000) How can I go about getting this numerical pattern. I...

How to make GNU octave reload scripts each time they are run

octave
I have a problem where Octave does not execute the newest version of recently edited scripts or functions if the working directory is a network drive. I have looked into it and it seems that Octave decides whether to reload these files based on the time stamp, and on my...

Ocave function for drawnow

matlab,plot,octave
I want to make a kind of real time audio tool in octave. In matlab there is the option to replot (drawnow) a (sub)plot and build a kind of gui around it. Is this in octave also possible i can't find anythind about it.. thanks...

Octave and Java: libjvm.so not found

java,debian,octave
I am trying to use WFDB toolbox for Matlab from Physionet in GNU Octave. One prerequisite is having GNU Octave 3.8.1 or later with the Java package, so I have compiled it for my Debian 7.8 and then installed Java package from within Octave. I am not sure to have...

Workaround for dynamically generating a structure - Matlab/Octave issues

matlab,indexing,data-structures,octave,cell-array
I have many, many sets of data in .csv format that I've organized by a file name standard so I can use regular expressions for the second time ever. I have, however, run into a slight problem. My data files are titled things like, "2012001_C335_2000MHZ_P_1111.CSV". There are four years of...

Using for-loop to generate vectors in Octave/Matlab

matlab,matrix,vector,octave
I am writing a script for generating the vectors and Hilbert matrix of order n,in which the vector x0 should change its size according to the size of the matrix. But there's an error message saying 'operator *: nonconformant arguments (op1 is 2x2, op2 is 12x1)' May I know why...

error: wavread: No such file or directory in Octave

octave
I take the same error messages on different computers trying to use Octave in terminal: wavread('example_audio.wav') error: wavread: No such file or directory error: called from: error: /usr/share/octave/3.8.1/m/audio/wavread.m at line 74, column 7 By the way, example_audio.wav is a working file (I tried in VLC player.) and I start Octave...

Matrix naming on loop

matlab,octave
I'm writing a piece of code where I can define a number of matrices that will be generated and then a loop generates them. The piece where I'm struggling is on the "naming" of the matrices, since I want to name as follows: matrix1; matrix2; etc. The code below is...

Integrating Octave interpreter into program compiled with GCC 4.8.1

windows,c++11,octave,embedding,gcc4.8
I'm trying to integrate Octave interpreter into my rigid body simulator compiled with GCC 4.8.1. Following steps posted in the official documentation (https://www.gnu.org/software/octave/doc/interpreter/Standalone-Programs.html) allow me to compile, link, and successfully execute the first example. Note, that I can link the executable with both mkoctfile.exe, or g++ when minGW 4.8.1 is...

Using arrayfun to apply two arguments of a function on every combination

octave,vectorization
Let i = [1 2] and j = [3 5]. Now in octave: arrayfun(@(x,y) x+y,i,j) we get [4 7]. But I want to apply the function on the combinations of i vs. j to get [i(1)+j(1) i(1)+j(2) i(2)+j(1) i(2)+j(2)]=[4 6 5 7]. How do I accomplish this? I know I...

how to draw a 3d line in octave/matlab

matlab,octave
I would like to draw a simple line between 2 Points in a 3D space using octave. I have tried to use plot3 with two 3d vectors: vec1 = [0 0 0] vec2 = [100 100 100] hold on; plot3(vec1,vec2,"-"); But this did not work for me. I found no...

Why is Calculating with the Cosine function so much faster than with the Secant Trig function?

matlab,octave,trigonometry
Why is Calculating with the Cosine function so much more faster than with the Secant Trig function? Is There a way to speed up the secant function? When calculating using the cosine and secant trig functions the time it takes vary a lot. Cosine = finally Done-elapsed time -36.7544sec- or...

Accessing 3-dimensional matrix by a 2-dimensional index in matlab/octave

matlab,matrix,octave
I have a 3 dimensional matrix (3rd dimension represents multiple copies of an M x N grayscale image). I'm taking the max value of each pixel across the images, giving me a max_val and max_ix matrix (2x2). I want to reference the original test matrix by the max_ix values. Example:...

parsing regular expression syntax issue matlab / octave

regex,matlab,octave
I can parse the regular expression in matlab / octave below: A = 'Var Name 123.5' [si ei xt mt] = regexp(A, '(\d)*(\.)?(\d)*$') number = str2num(mt{1}) number = 123.50 But I get a syntax error below most likly caused due to the ] A='[angle_deg = 75.01323334803705]' [si ei xt mt]...

Making for loop and if statment and increasing speed using matlab / octave

matlab,octave
I'm trying to see if I can improve the speed of a for loop and an if condition statement. Basically it does a lookup on non repeating key values into an array and gets the value from another column. If I run 100000 values it takes about 13 seconds see...

MATLAB Hamming-window

matlab,octave
I am using Hamming window using the first principle equation to produce a window of length 23. Below is the code that I am using: >> M=23 >> w = .54 - .46*cos(pi*(0:M-1)'/M) >> plot(w) Why is the graph not displaying a popper Hamming window please? Attached are the equation...

Need help parse error GNU Octave

linux,octave
I try writing the linear & nonlinear regression on GNU Octave as a part of my final project for Numerical Method class. Still I have one error in my code it's a simple parse error but I don't know how to fix it. I try to fix the syntax or...

Octave: How to load grayscale images in double format?

octave
I am using the imread function in Octave to load an image: image = imread ("data/images/image1.jpg")(:); This is apparently loading the image as a matrix of integers with values 0-255. I want to load it as matrix of doubles with values 0.0-1.0. I can convert it like this. doubleImage =...