octave

two arrays defining 2d coordinates, as array indices, in matlab/octave

风流意气都作罢 提交于 2019-12-17 14:01:07
问题 I have a 2D array, call it 'A'. I have two other 2D arrays, call them 'ix' and 'iy'. I would like to create an output array whose elements are the elements of A at the index pairs provided by x_idx and y_idx. I can do this with a loop as follows: for i=1:nx for j=1:ny output(i,j) = A(ix(i,j),iy(i,j)); end end How can I do this without the loop? If I do output = A(ix,iy), I get the value of A over the whole range of (ix)X(iy). Thank you, Jason 回答1: A faster way is to use linear indexing

How to embed the GNU Octave in C/C++ program?

让人想犯罪 __ 提交于 2019-12-17 10:54:42
问题 I want to calculate some matrix algorithms using the GNU Octave library. I know I can use C/C++ API of Octave for basic use. However the method I want to use is not in the default packages of Octave. So how to use Octave's control package in the C/C++ program? 回答1: Something like this embed.cpp #include <iostream> #include <octave/octave.h> int main(int argc,char* argv) { int embedded; octave_main(argc,argv,embedded=0); return embedded; } Then mkoctfile embed.cpp --link-stand-alone -o embed

Sweep / chirp signal ends at incorrect frequency

一个人想着一个人 提交于 2019-12-17 09:57:42
问题 I'm creating a sweep / chirp signal using matlab / octave and my ending signal seems to be ending at the wrong frequency. How can I fix it so that the signal ends at the correct frequency. PS: I can't use the chirp command in octave because I'm creating a chirp / sweep signal using a specific equation. Example code with simple equation. and plot of problem %test sweep / chirp clear all,clc freq1=20; %start freq freq2=200; %end freq fs=44100; dur=1; %duration of signal in seconds t = linspace

Octave/Matlab: Adding new elements to a vector

自作多情 提交于 2019-12-17 08:51:56
问题 Having a vector x and I have to add an element ( newElem ) . Is there any difference between - x(end+1) = newElem; and x = [x newElem]; ? 回答1: x(end+1) = newElem is a bit more robust. x = [x newElem] will only work if x is a row-vector, if it is a column vector x = [x; newElem] should be used. x(end+1) = newElem , however, works for both row- and column-vectors. In general though, growing vectors should be avoided. If you do this a lot, it might bring your code down to a crawl. Think about it

Octave-Gnuplot-AquaTerm error: set terminal aqua enhanced title “Figure 1”…unknown terminal type"

大憨熊 提交于 2019-12-17 08:02:30
问题 I've installed Octave and gnuplot via Homebrew, and downloaded AquaTerm.dmg. When I try to plot, I get the following message: octave:4> plot(x,y) gnuplot> set terminal aqua enhanced title "Figure 1" font "*,6" ^ `line 0: unknown or ambiguous terminal type; type just 'set terminal' for a list` In a bash terminal set terminal , set Terminal , set term , (and the same, followed by "aqua" too) etc gives nothing. I've tried plotting again from octave having the "AquaTerm" already open, but nothing

Create a zero-filled 2D array with ones at positions indexed by a vector

戏子无情 提交于 2019-12-17 04:08:40
问题 I'm trying to vectorize the following MATLAB operation: Given a column vector with indexes, I want a matrix with the same number of rows of the column and a fixed number of columns. The matrix is initialized with zeroes and contains ones in the locations specified by the indexes. Here is an example of the script I've already written: y = [1; 3; 2; 1; 3]; m = size(y, 1); % For loop yvec = zeros(m, 3); for i=1:m yvec(i, y(i)) = 1; end The desired result is: yvec = 1 0 0 0 0 1 0 1 0 1 0 0 0 0 1

Create a zero-filled 2D array with ones at positions indexed by a vector

二次信任 提交于 2019-12-17 04:08:32
问题 I'm trying to vectorize the following MATLAB operation: Given a column vector with indexes, I want a matrix with the same number of rows of the column and a fixed number of columns. The matrix is initialized with zeroes and contains ones in the locations specified by the indexes. Here is an example of the script I've already written: y = [1; 3; 2; 1; 3]; m = size(y, 1); % For loop yvec = zeros(m, 3); for i=1:m yvec(i, y(i)) = 1; end The desired result is: yvec = 1 0 0 0 0 1 0 1 0 1 0 0 0 0 1

PHP exec octave sh in Windows

♀尐吖头ヾ 提交于 2019-12-14 04:09:59
问题 I'm trying to execute the following octave sh file in php using the exec command running in Windows 2008. This command works in Unix but I don't know why it doesn't work in Windows. Seems that the working directory of Octave is C:\Windows\system32\config\systemprofile Please advice. exec("octave ./d_test.sh"); 回答1: Solved :) I edited the octaverc in 'c:\software\Octave\Octave3.6.2_gcc4.6.2\share\octave\site\m\startup' with addpath("C:\\Program Files (x86)\\Apache Software Foundation\\Apache2

Multiply matrices layer by layer

谁都会走 提交于 2019-12-14 03:26:57
问题 I want to do this without loops: % A ~ 4x2x3; B ~ 4x3x2; C ~ 4x2x2; for i=1:4 C(i,:,:) = squeeze(A(i,:,:))*squeeze(B(i,:,:)); end Thanks! 回答1: Haven't benchmarked this (so this is not guaranteed to be faster), but here goes: [L, ma, na] = size(A); [L, mb, nb] = size(B); AX = reshape(permute(A, [2 1 3]), [], na); BX = reshape(permute(B, [2 3 1]), mb, []); CX = reshape(permute(reshape(AX * BX, ma, L, nb, L), [1 3 2 4]), ma, nb, []); C = permute(CX(:, :, 1:L + 1:end), [3 1 2]); Note that you

Matlab\Octave haven't the same result with contourf

a 夏天 提交于 2019-12-13 23:46:54
问题 I have a problem to use contourf in octave. If I test the following code in octave and matlab, the result is not at all the same. The result with Matlab is good. A1=[38 44 51 58 65 72 79 86 93 100 38 44 51 58 65 72 79 86 93 100 38 44 51 58 65 72 79 86 93 100 38 44 51 58 65 72 79 86 93 100 38 44 51 58 65 72 79 86 93 100 38 44 51 58 65 72 79 86 93 100 38 44 51 58 65 72 79 86 93 100 38 44 51 58 65 72 79 86 93 100 38 44 51 58 65 72 79 86 93 100 38 44 51 58 65 72 79 86 93 100] B1=[ 1 1 1 1 1 1 1 1