I am using the Octave plot function to plat a 2D graph. I want to scale the x axis by 2x (no change to y axis). i.e. the distance between each unit in x axis is doubled.

How do I do that in Octave?

Tag: octave

I am using the Octave plot function to plat a 2D graph. I want to scale the x axis by 2x (no change to y axis). i.e. the distance between each unit in x axis is doubled.

How do I do that in Octave?

```
set(gca,'dataaspectratio',[2 1 1])
```

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...

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

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

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...

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...

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...

matlab,loops,image-processing,octave

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

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...

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...

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...

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.

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...

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...

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...

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

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

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...

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...

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 .'....

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'')') ...

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.

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

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

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

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...

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...

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

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...

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 =...

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...

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....

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...

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

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...

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

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(:)) ...

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

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...

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....

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...

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...

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...

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...

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] =...

#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...

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...

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...

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)], '-') ...

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...