Your regular expression from the first method is fine assuming that you are looking for a number at the end of the string. Because you have an ending ] character in your new string, your regular expression won't work because your string does not end in a number. As such,...

One approach - %// Get size of 3D input array [m,n,~] = size(test); %// Calculate 2D starting, offset & finally actual indices array start_idx = bsxfun(@plus,[1:m]',[0:n-1]*m); %//' offset_idx = m*n*(max_ix-1); actual_idx = start_idx + offset_idx; %// Index into 3D input array to extract specific elements, for desired output max_val =...

Yup. Use the 'FontName' attribute. If you want to change the size, use 'FontSize', and finally for the colour, use the 'Color' attribute... so something like this: text(1, 1, '7', 'FontName', 'verdana', 'FontSize', 16, 'Color', 'blue'); Change the above attributes to whatever you want, but I've made the font size...

You have more opening brackets ( than closing ones ), that's a syntax error. It should be: plot(freq1, abs(fft1/max(fft1)),xlabel('f(Hz)'), ylabel('Amplitude I(f)')); ...

The maximum path length to be used on Windows is 260. You may work around this issue but you will probably run into the next. I strongly recommend to change the struchture as other octave functions and other software will run into similar issues. If you really can`t change the...

matlab,graphics,octave,fill,figure

You can use the following trick: Fill normally, as you do in your code. No need for coloring the edges; it will be done later. Draw a white rectangular patch to cover the part you don't want filled. No edge color here either. Plot the lines on top of that....

You could use histc. But histc considers equality at the left edge of each bin, not at its right edge: bincounts = histc(x,binranges) counts the number of values in x that are within each specified bin range. The input, binranges, determines the endpoints for each bin. The output, bincounts, contains...

windows,c++11,octave,embedding,gcc4.8

I just learned that there is a newer Octave version available at http://mxeoctave.osuv.de/ which was compiled with GCC 4.9.2. This version of GCC works for me perfectly and the second example provided in the documentation started to work when compiled with g++ provided with the distribution.

P files are protected, you can't open them, that's the whole point of them. You should still be able to run them in MATLAB, but I'm not sure if they'll work in Octave.

I apologize that the following is a bit messy. I did everything manually because I'm not sure how else to do it. First you need to know how MATLAB stores frequency domain data. Take the following example: N = 100; % number of samples Fs = 100; % sampling frequency...

Check if you have the documentations installed ! Depending on how you have to installed octave, you have to specify somehow to install also the documentations. If you need more help, then provide more info, on how octave has been installed. If you have installed through home-brew, try to reinstall...

arrays,matlab,function,matrix,octave

You are trying to create a script file, but you are also trying to define a function within a script file which is not allowed. Script files are created to batch execute commands from the top of the file to the bottom. They are not designed to have functions defined...

You are measuring M(ega)FLOPS (1e6), not G(iga)FLOPS (1e9)

Approach #1 This could be really efficient with ismember - lookupval = sort(lookupval); %// Do sorting at the start sort_comb_array = [lookupval zeros(size(lookupval))]; %// Setup output array [idA,idB] = ismember(array(:,1),lookupval); %// Get matching IDs sort_comb_array(idB(idA),2) = array(idA,2); %// Index into second column %// of array and get corresponding values Approach...

Using assignin, you can write a variable to the workspace with a custom name. for i=1:matrices_to_generate matrix = rand(2,2); assignin('base', strcat('matrix', num2str(i)), matrix); end; ...

matlab,octave,curve-fitting,data-fitting

Your function y = a(0.01 − b*n−cx) is in quite a specific form with 4 unknowns. In order to estimate your parameters from your list of observations I would recommend that you simplify it y = β1 + β2β3x This becomes our objective function and we can use ordinary least...

You can use mouse clicks combined with ginput. What you can do is put your code in a while loop and wait for the user to click somewhere on the screen. ginput pauses until some user input has taken place. This must be done on the figure screen though. When...

Using a loop %// create the data x=[9,8,7,6,5,4,3,2,1] array_all = bsxfun( @times, x(:), [1 .5 .25] ); Start pruning n = numel(x); valid = false(n,1); %// at first, only first line is valid valid(1) = true; for ii=2:n, %// first line is valid by default valid(ii) = ~any( reshape( array_all(...

From reading manual I discovered help function, here is output of run from command line : ...

The fifo class works, but only up to a certain size. The max size in bytes of a fifo can be found by running: cat /proc/sys/fs/pipe-max-size 1048576 Below is the code that I wrote for an in-memory fifo. It's fairly crude but it works well: 1; % Prevent Octave from...

Say you have a vector of x-coordinates X, and y-coordinates Y, and an indicator vector k of 1's and -1's, you could do plot(X(k>0),Y(k>0),'b',X(k<0),Y(k<0),'g') which uses logical indexing to pick out the elements with k=1 and k=-1 separately, or use scatter and use the k vector to colour the points....

On octave 3.8.2 at least, you get a bit more information. octave-cli-3.8.2:2> which mldivide 'mldivide' is a built-in function from the file libinterp/corefcn/data.cc this file can be found on the octave repository. That specific function is on line 6083: DEFUN (mldivide, args, , "-*- texinfo -*-\n\ @deftypefn {Built-in Function} {}...

Use evalin with the 'caller' option. That is, replace your line builtin('clear') by evalin('caller', 'builtin(''clear'')') This will clear all variables from the workspace of the caller function. Should you want want to clear all variables from the Matlab base workspace, use the 'base' option: evalin('base', 'builtin(''clear'')') ...

matlab,geometry,octave,numerical-methods

Using MATLAB built-in functions The simplest way to do it would be to define the function as it is, then use the fsolve() function. For example (the code is not tested): function y = cctang(t) %t is a 1-by-4 line vector (first two members = t1, last two members =...

matlab,indexing,data-structures,octave,cell-array

The problem is that when you get to the for loop that is causing a problem, data already exists and is a struct array. octave> data data = 8x1 struct array containing the fields: name date bytes isdir datenum statinfo When you select a field from a struct array you...

matlab,octave,interrupt,halt,runcommand

It is not possible to implement such a stop condition outside the script, matlab is single threaded and nothing outside is executed. Maybe a conditional breakpoint is what you are looking for. dbstop in haltable at 5 if (environment>.5) You have to replace 5 with the correct line number. This...

What you want is to plot a line on 2^24. However, there are too many points for you computer probably, and you run out of memory I am guessing that you'll need to plot your other inequality as well. Something like x=1:100:2^20; % As Zoran and others suggested, You may...

You don't need to install the java package. The functions in the java package have been merged into the Octave core language for the 3.8 release. You don't need to do anything, java should work out of the box for you (provided you didn't mess up while building it). If...

Not having received any answers, I'll answer my own question :-) I haven't worked out what the root cause of the problem and how to fix it, but I have found a workaround. It seems that the problems lies with the fact that the elements in the 4th column are...

Aside from initializing runningValue to empty, you might as well try reducing the number of appendition, which is an O(n) operation. Instead of appending an element on every loop, you can double the size of the array when it is full. This way, you reduce the number of appendition from...

You are looking for numpy.transpose np.transpose( np.expand_dims(A, axis=2), (2, 1, 0) ) Since numpy does not have trailing Singleton dimensions by default, you need to explicitly add it using np.expand_dims...

You can overload ginput at the beginning of the octave session (in your .octaverc file for instance) ginput = @() warning("ginput has been disabled") This is defining a new function with the same name. The original ginput will "screened" by this new function. But a clear ginput would get rid...

This is a known problem when using the OpenGL toolkits (graphics_toolkit FLTK) which is default in octave3.8.x. Previous versions used gnuplot for printing. So you have two choices: Switch back to gnuplot with "graphics_toolkit gnuplot" before doing any plotting. You may also add this to your .octaverc so it's set...

Function File: VI = interpn (X1, X2, ..., V, Y1, Y2, ...) Function File: VI = interpn (V, Y1, Y2, ...) Perform N-dimensional interpolation, where N is at least two. Each element of the N-dimensional array V represents a value at a location given by the parameters X1, X2, ...,...

The code you wrote is a bit obfuscated. One way to make this more clear is to do: frac_value = find(xmin > 0 & xmin < 1); What you are essentially doing is finding the indices of xmin that are both greater than 0 and less than 1. Instead of...

This should be quite fast: n = 9; a1 = bsxfun(@min, min(1:n,n:-1:1).', 1:ceil(n/2)); a2 = a1(:,end:-1:1); ...

matlab,octave,numerical-methods,numerical

Method #1 - Using (-1)^x Just use a linear increment operator to go from 0 to 200000 and multiply the sequence by (-1)^(x+1) to allow the sign of the sequence to alternate: x = 0:200000; y = ((-1).^(x+1)) .* x; The addition of the +1 is important so that the...

matlab,signal-processing,octave

DC isolation is basically low-pass filtering. You want to remove all the high-frequency components, while preserving the low. There are tons of approaches to this problem, but it looks like you're looking for something quick and simple. One of the simplest forms of low-pass filter is the moving average. It's...

That's two questions: drawnow() exists in Octave for a very long time building a GUI in Octave will require at least version 4.0.0 (still unreleased) and qt graphics toolkit ...

In Matlab you call plot3 with three vectors (or matrices), each specifying the x, y and z coordinates respectively. So: plot3([vec1(1) vec2(1)], [vec1(2) vec2(2)], [vec1(3) vec2(3)], '-') ...

arrays,matlab,matrix,octave,linear-algebra

The notation eye(10)(a,:) in Octave means: build the size-10 identity matrix (eye(10)) and then pick its rows in the order given by a (note that a is used as the first index, which corresponds to rows, and : as second index, which means "take all columns"). So, for example, the...

On a mathematical level you could argue that all of these expressions return the same: size(a:b:c) size(a/b:c/b) size(0:c/b-a/b) Now you end up with integers from 0 to that term, which is: floor((c-a)/b+1) There is one problem: Floating point precision. The colon operator does repeated summing, don't know any possibility to...

It's pretty easy to find rows matching a certain condition in octave: m(:,1) == 1 # m(i, 1) = 1 m(:,3) == 1 # m(i, 3) = 1 You could combine multiple conditions using octave & (logical and) and | (logical or) operators: (m(:,1) == 1) & (m(:,3) == 1)...

regex,matlab,pattern-matching,octave,maple

To find the shortest pattern that upon repetition generates the whole string, you can use regular expressions as follows: result = regexp(str, '^(.+?)(?=\1*$)', 'match'); Some examples: >> str = '12341234123412341234'; >> result = regexp(str, '^(.+?)(?=\1*$)', 'match') result = '1234' >> str = '1234123412341234123'; >> result = regexp(str, '^(.+?)(?=\1*$)', 'match') result...

matlab,random,octave,random-walk

No need for a loop: N = 100000; t = 1:N; x = cumsum(2*(rand(1,N)<.5)-1); plot(t,x) For the 2D case you could use the same approach: N = 100000; %// t = 1:N; it won't be used in the plot, so not needed x = cumsum(2*(rand(1,N)<.5)-1); y = cumsum(2*(rand(1,N)<.5)-1); plot(x,y) axis...

Thanks to Fred Senese and rayryeng for the assist. I know someone may need this so here's some example code. This bit of code allows you to directly access maxima's symbolic solver from octave (allows you to execute multiple lines of maxima's commands). Since octave doesn't have a good symbolic...

The easiest way with Matlab (if you have the curve fit toolbox) is to use the cftool. This gives you a gui which you can import the data and play with the best fit. If you need to build this into a code then you can use the best function...

Octave does not have a native implementation of sec, it uses cos to do so. Check edit sec.m for details. The difference is caused by function calls of nargin in sec function call overhead for sec dividing the values To get rid of the first two factors, use 1./cos(x) instead...

Most likely is the concatenation of three strings resulted from displaying a NaN and two floating point numbers. For example: fprintf(1, '%d%d%.0e\n', NaN, 450, 0.5) Later edit: Given the new information added to the original question, the most likely cause is f1 variable being a 3-element vector of doubles, with...

matlab,octave,linear-programming,glpk

If you look at the octave help you will find this lpsolver (default: 1) Select which solver to use. If the problem is a MIP problem this flag will be ignored. 1 Revised simplex method. 2 Interior point method. So really in only differs on terms of efficiency in certain...

matlab,octave,linear-programming,glpk

I could sort out my problem. It is happening because of some of the variables are having value 0.000000000000000027773 or 0.99999999999999999. So if I do some pre-processing like making those 0.000000000000027773 values 0 or 0.99999999999999999 1 then GLPK gives feasible solution

The problem is you are comparing a n*1 vector with a 1*n vector. In this case octave broadcasts the variable (similar to matlabs bsxfun) resulting in a matrix. The sum of a matrix is a vector. Use if any(pMinC>0) to fix the problem. ...

The Moore–Penrose pseudo inverse, which is the basis for Matab and octave's pinv, is implemented via completely different algorithm than the inv function. More specifically, singular value decomposition is used, which require's finite-valued matrices (they also can't be sparse). You didn't say if your matrices are square or not. The...

The typical way to debug such a problem is to enable debug_on_error debug_on_error(1); The run your script again. This time it will stop in previsao with a debug> prompt. Now you can instect "eul" and "heu", for example the first step would be size(eul) size(heu) x ti then it should...

What you want do is called brodcasting. If you are using Octave 3.8 or later, the following will work fine: octave> X = (1:5)' X = 1 2 3 4 5 octave> P = (1:5) P = 1 2 3 4 5 octave> X .^ P ans = 1 1...

matrix,octave,matrix-multiplication

In Octave you could set/update any part of the original matrix. For example, here is how to add vector B to the second row of a matrix A: A(2,:) = A(2,:) + B; ...

matrix,octave,matrix-multiplication,broadcasting

This is because Octave (in a notable difference from Matlab) automatically broadcasts. The * operator in Octave is the matrix multiplication operator. So in your case a*b would output (in Matlab as well) a*b ans = 1 2 3 2 4 6 3 6 9 which should be expected. The...

XGetUtf8FontAndGlyph should be in libfltk.so.1.3. nm -D /usr/lib/x86_64-linux-gnu/libfltk.so.1.3 |grep XGetU 00000000000c2fc0 T XGetUtf8FontAndGlyph It's very likely that this is a problem with your configure flags for fltk and not GNU Octave. Just try it with the default settings first. You can test if the UTF8 stuff with OpenGL is okay...

In Octave, for finding summations between two vectors, you can use a truly vectorized approach with broadcasting like so - out = reshape(ii(:).' + jj(:),[],1) Here's a runtime test on ideone for the input vectors of size 1 x 100 each - -------------------- With FOR-LOOP Elapsed time is 0.148444 seconds....

The issue is that your n is going from 0 to M-1 not from -M to M Try this instead: M = 23 w = .54 + .46*cos(pi*(-M:M)/M) plot(w) ...

You can shift the original ColorOrder in current axes so that the new plot starts from the same color: h=plot(x1'); set(gca, 'ColorOrder', circshift(get(gca, 'ColorOrder'), numel(h))) plot(x2'); You can wrap it in a function: function h=plotc(X, varargin) h=plot(X, varargin{:}); set(gca, 'ColorOrder', circshift(get(gca, 'ColorOrder'), numel(h))); if nargout==0, clear h end end and...

matlab,bit-manipulation,octave

That or is equivalent to an addition when dealing with integers result = bitshift(bi2de(bitget(a,1:2)),8) + b; e.g a = 01010111 b = 10010010 result = 00000011 100010010 = a[2]*2^9 + a[1]*2^8 + b an alternative method could be result = mod(a,2^x)*2^y + b; where the x is the number of...

The simplest way to do this operation is to simply: X(:,2) -= 2000; which is also a lot easier to read. This will modify the second column X "in place". If you want to make a copy of it where the second column is subtracted, then simply: xx = X;...

If you really need two lines, try: for ii=1:6 ii*2-1 ii*2 end ...

#include <iostream> should be #include <stdio.h> and std::cout << a_matrix; should be printf("%d", a_matrix); But <octave/oct.h> can not be used in C: A.1.1 Getting Started with Oct-Files The first critical line is #include which makes available most of the definitions necessary for a C++ oct-file. Note that octave/oct.h is a...

Use scatter3: N_colors = 64; colormap(cool(N_colors)); # point positions (your data(:, 1:3)) [x, y, z] = peaks (20); # this are the color indexes in the colormap (your data(:, 4)) c_index = fix(rand(size(x)) * N_colors); marker_size = 8; scatter3(x(:), y(:), z(:), marker_size, c_index(:)) ...

I believe that in Octave version 4.0 there is experimental support for classdef-based object-oriented code, including enumeration blocks. Edit: looks like I was wrong, and enumerations are not yet supported, as indicated in the comment below from @carandraug (who I believe is an Octave developer, so probably knows better then...

You could do the calculation of the fraction yourself. Therefore you need to calculate $d$ directly. Then you can get all values of the numerators and the denominators and multiply them by hand and make sure that the result will not get too big. The following code is poorly in...

Note Before reading. You seem to be confusing the choice of colormap with colour segmentation. It is important to note: Colormap: used for user-friendly visualization. You don't use the colours of a colormap as data, you use the original data. However human eyes see more friendly a colour picture than...

You can address the data in each pixel with the CData property of the image without having to close and redraw the figure, axes, or axes object over and over. Ends up being about 1.5x - 2x faster than trying to generate a new image object or just calling imagesc()...

The easiest solution would be to call file1 in file2: function file2() variable = file1(); variable2 = variable*2; % do you want to return variable2 as the output of file2? endfunction EDIT If your function returns more than one variable, the process is exactly the same, i.e.: function [x,y,z] =...

matlab,loops,image-processing,octave

Like that- for z=1:num fname=sprintf ('plane%d.tif', z); imwrite (IWindow, gray (256), fname); end ...

There are many ways to test if a vector or array x contains strictly equal elements. Here are a few. Note that (:) is necessary only if dealing with an array of more than one dimension; for vectors you can remove that: all(x(1)==x(:)) max(x(:))==min(x(:)) all(diff(x(:)))==0 numel(unique(x(:)))==1 If x is of...

Use scatter for this instead of plot: %// Making dummy data: n = 10; points = rand(n,2); points(:,3) = randi(3,n,1); %//Setting a colormap: note that you should not use a cell array for this! c=[1 0 0; 0 1 0; 0 0 1] colormap(c) %//plot scatter(points(:,1), points(:,2), [], points(:,3)) ...

octave,numerical-methods,numerical-integration

I have tried your function in Matlab. Your code is not stalling. It is rather that the size of trap_1_midpoints increases exponentionaly. With that the computation time of trap_1 increases also exponentionaly. This is what you experience as stalling. I also found a possible bug in your code. I guess...

arrays,matrix,multidimensional-array,types,octave

I believe that the ND in NDArray stands for N-Dinensional. N being a number when you say it out aloud like 2-Dimensional Array etc.

I guess the length of each line is not constant which would make it impossible to use fseek to set the file pointer to the beginning of a line without reading it first (which would the make setting the filepointer useless). You write in another question, that your input file...

This version is working for me on Matlab. 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 In the 4th row of F the white space is treated as a separator for two entries, it should be removed. Additionally, there is an unnecessary bracket....

The problem is with the vector, and line x0(1:k)=1; which does not change the size of the vector when k = 2. Instead it sets the first k elements of x0 to 1. I would assume that x0 is already set elsewhere as a 12-dimensional vector. You could try x0...

I think there is a problem in way how you use the mean() and std() functions and also maybe subscripted assignment is an issue too. I am not sure but please try these codes below as your function definition: 1. Row based normalization: function [X_norm, mu, sigma] = featureNormalize(X) X_norm...

Seems that you forgot to load the signal package. You have to install and load it in order to use the butter function: pkg install -forge signal pkg load signal [b,a] = butter (5,0.2); Please take a look in the Octave documentation. It explains how to install and how to...

Double check the file name. Use tab to auto complete the filename to check if its found on your path.

The line before that case label has mismatched parentheses: plot((alpha.*(x^a1)) ...

you probably want something like NetLab. The authors state that most of it works in Octave. There is a page with examples that comes from a book about the software. From the Intro on the site it looks like netopt is similar to fitnet in functionality, if not necessarily in...

No, there is no way to directly read it as doubles. It doesn't make sense anyway, because the image is an integer in the file, so integers will always have to be read first. If a conversion into another type is to be done, it makes sense that it does...

matlab,octave,pca,missing-data,least-squares

Thanks for all your help. I went through the references and was able to find their matlab code on the als algorithm from two of the references. For anybody wondering, the source code can be found in these two links: 1) http://research.ics.aalto.fi/bayes/software/index.shtml 2) https://www.cs.nyu.edu/~roweis/code.html...

matlab,image-processing,machine-learning,octave,k-means

edge in MATLAB / Octave returns a binary / logical matrix. kmeans requires that the input be a double or single matrix. Therefore, simply cast ed to double and continue: ed=edge(de,"canny"); imshow(ed); ed = double(ed); %// Change j=kmeans(ed,3); ...

In Octave you can use bwboundaries (but I will welcome patches that implement bwtraceboundaries) octave:1> pkg load image; octave:2> bw = logical (imread ("http://i.stack.imgur.com/BoQPe.jpg")); octave:3> boundaries = bwboundaries (bw); octave:4> boundaries = cell2mat (boundaries); octave:5> imshow (bw); octave:6> hold on octave:7> plot (boundaries(:,2), boundaries(:,1), '.g'); There are a couple of...

I don't know why it isn't working. ' is actually listed as an operator in the docs. But as a workaround, you could use the transpose function. y = [4, 5, 6]; y_transpose = transpose(y); Though I should note that ' is the complex conjugate transpose. Normal transpose is .'....

Because of the dependency between iterations to obtain results for each new column with respect to the previous column, it seems you would need at least one loop there, but do all operations within a column in a vectorized fashion and that might speed it up for you. The vectorized...

You can use rehash this will Octave reinitialize its directory cache, see http://octave.sourceforge.net/octave/function/rehash.html . You can also use clear functionName which should clean all variables in the function and trigger a reload (you script would be called functionName.m). I got this from the Octave mailing list: http://lists.gnu.org/archive/html/help-octave/2009-03/msg00212.html...