octave

How do I play a sound in Octave?

冷暖自知 提交于 2019-11-30 13:57:26
问题 Octave appears to assume that a specific sound playing utility will be available on a system but doesn't seem to provide the ability to specify an alternate. In the error below, Octave is looking for ofsndplay , which is not a utility available on all systems. octave:38> sound(beamformed_20) sh: ofsndplay: command not found Is there an Octave configuration setting or code fragment that I can use to specify an system-appropriate utility? 回答1: I've overridden the playaudio function from octave

Periodogram in Octave/Matlab vs Scipy

扶醉桌前 提交于 2019-11-30 13:05:45
I am porting some matlab code to python using scipy and got stuck with the following line: Matlab/Octave code [Pxx, f] = periodogram(x, [], 512, 5) Python code f, Pxx = signal.periodogram(x, 5, nfft=512) The problem is that I get different output on the same data. More specifically, Pxx vectors are different. I tried different windows for signal.periodogram, yet no luck (and it seems that default scypy's boxcar window is the same as default matlab's rectangular window) Another strange behavior is that in python, first element of Pxx is always 0, no matter what data input is. Am i missing

How to output matrix dimensions together with its content?

ぐ巨炮叔叔 提交于 2019-11-30 12:38:05
Is it possible to make GNU Octave to output matrix dimensions together with its content? For example, it should produce smth. like this: octave:1> X = [1 2; 3 4] X [2x2] = 1 2 3 4 octave:2> X(1,:) ans [1x2] = 1 2 In MATLAB, create display.m in a folder called @double somewhere in your path with this content: function display(v) name = inputname(1); if isempty(name) name = 'ans'; end s = num2cell(size(v)); fprintf('\n%s [%d%s] =\n\n', name, s{1}, sprintf('x%d', s{2:end})); builtin('disp', v); end This way you override the display method for class double , and get exactly what you have described

Why is Octave slower than MATLAB?

我怕爱的太早我们不能终老 提交于 2019-11-30 11:47:08
问题 I have been using Octave and MATLAB for a few projects, and I've come across a few questions. This question Why/when should I prefer MATLAB over Octave?) answered several, but there is still one lingering... I've read a number of posts/other sources comparing performance of Octave and MATLAB, and I've run some of my own tests on standard scripts that confirm the general consensus that Octave is generally much slower than MATLAB for standard operations (iterated, of course, so that the

Replace all zeros in vector by previous non-zero value

旧城冷巷雨未停 提交于 2019-11-30 10:54:00
Matlab/Octave algorithm example: input vector: [ 1 0 2 0 7 7 7 0 5 0 0 0 9 ] output vector: [ 1 1 2 2 7 7 7 7 5 5 5 5 9 ] The algorithm is very simple: it goes through the vector and replaces all zeros with the last non-zero value. It seems trivial, and is so when done with a slow for (i=1:length) loop and being able to refer to the previous element (i-1), but looks impossible to be formulated in the fast vectorized form. I tried the merge() and shift() but it only works for the first occurrence of zero, not an arbitrary number of them. Can it be done in a vectorized form in Octave/Matlab or

Using SVD to compress an image in MATLAB

匆匆过客 提交于 2019-11-30 10:48:50
问题 I am brand new to MATLAB but am trying to do some image compression code for grayscale images. Questions How can I use SVD to trim off low-valued eigenvalues to reconstruct a compressed image? Work/Attempts so far My code so far is: B=imread('images1.jpeg'); B=rgb2gray(B); doubleB=double(B); %read the image and store it as matrix B, convert the image to a grayscale photo and convert the matrix to a class 'double' for values 0-255 [U,S,V]=svd(doubleB); This allows me to successfully decompose

Why/when should I prefer MATLAB over Octave?

萝らか妹 提交于 2019-11-30 10:36:55
问题 In our shoestring operation we need to prototype algorithms in some higher-level language before committing to a C implementation on embedded hardware. So far we have been using MATLAB to do that, but the licensing costs are beginning to hurt. We're considering porting our MATLAB code to Octave. Is there any particular reason not to do that? Will we break any compatibility, especially if we have external partners who insist on using MATLAB? Are there any performance penalties we can expect?

Matlab, how to calculate AUC (Area Under Curve)?

落花浮王杯 提交于 2019-11-30 09:50:18
I have the file data.txt with two columns and N rows, something like this: 0.009943796 0.4667975 0.009795735 0.46777886 0.009623984 0.46897832 0.009564759 0.46941447 0.009546991 0.4703958 0.009428543 0.47224948 0.009375241 0.47475737 0.009298249 0.4767201 [...] Every couple of values in the file correspond to one point coordinates (x,y). If plotted, this points generate a curve. I would like to calculate the area under curve (AUC) of this curve. So I load the data: data = load("data.txt"); X = data(:,1); Y = data(:,2); So, X contains all the x coordinates of the points, and Y all the y

How do I play a sound in Octave?

北慕城南 提交于 2019-11-30 08:58:27
Octave appears to assume that a specific sound playing utility will be available on a system but doesn't seem to provide the ability to specify an alternate. In the error below, Octave is looking for ofsndplay , which is not a utility available on all systems. octave:38> sound(beamformed_20) sh: ofsndplay: command not found Is there an Octave configuration setting or code fragment that I can use to specify an system-appropriate utility? I've overridden the playaudio function from octave with the following function. This will work only after installing sox . sudo apt-get install sox (in ubuntu)

Create faster Fibonacci function for n > 100 in MATLAB / octave

孤者浪人 提交于 2019-11-30 08:53:24
I have a function that tells me the nth number in a Fibonacci sequence. The problem is it becomes very slow when trying to find larger numbers in the Fibonacci sequence does anyone know how I can fix this? function f = rtfib(n) if (n==1) f= 1; elseif (n == 2) f = 2; else f =rtfib(n-1) + rtfib(n-2); end The Results, tic; rtfib(20), toc ans = 10946 Elapsed time is 0.134947 seconds. tic; rtfib(30), toc ans = 1346269 Elapsed time is 16.6724 seconds. I can't even get a value after 5 mins doing rtfib(100) PS: I'm using octave 3.8.1 If time is important (not programming techniques): function f = fib