octave

How to add vectors with different length?

丶灬走出姿态 提交于 2019-12-04 04:37:13
I would like to add two vectors with different lengths in Matlab or Octave. E.g. aa = [1 2 3 4]; bb = [100 100]; Which should result in a vector cc containing cc = [101 102 3 4] Can anyone figure out how to do this? Update: This is the code I ended up with for the signals that I then later convert to grey scale images. load train; t = y; load chirp; c = y; tc = c + [t; zeros(length(c) - length(t),1)]; plot(1:length(tc),tc) Thank you very much to you all =) This doesn't make any sense mathematically, but if you insist, you can do this: cc = aa + [bb zeros(1,2)]; For the 1-D case dealing with a

Generate matrix of bits

痞子三分冷 提交于 2019-12-04 04:33:51
问题 I would like to take an integer n defining the number of bits in my communication code and a vector defining the alphabet I am assigning to bits 0:n-1 , and output a matrix/cell array containing the alphabetic notation for each state, i.e.: function M = mycommarray(3,[-1,1]) produces M = [{-1,-1,-1}, {-1,-1,1}...] I tried doing this an easier way with dec2bin(0:7,3) , but there doesn't seem to be a quick way to make the zeros into -1 s. Is there anything close to prepackaged that does this?

Any reason why Octave, R, Numpy and LAPACK yield different SVD results on the same matrix?

泪湿孤枕 提交于 2019-12-04 03:40:20
I'm using Octave and R to compute SVD using a simple matrix and getting two different answers! The code is listed below: R > a<-matrix(c(1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,1,1,1), 9, 4) > a [,1] [,2] [,3] [,4] [1,] 1 1 0 0 [2,] 1 1 0 0 [3,] 1 1 0 0 [4,] 1 0 1 0 [5,] 1 0 1 0 [6,] 1 0 1 0 [7,] 1 0 0 1 [8,] 1 0 0 1 [9,] 1 0 0 1 > a.svd <- svd(a) > a.svd$d [1] 3.464102e+00 1.732051e+00 1.732051e+00 1.922963e-16 > a.svd$u [,1] [,2] [,3] [,4] [1,] -0.3333333 0.4714045 -1.741269e-16 7.760882e-01 [2,] -0.3333333 0.4714045 -3.692621e-16 -1.683504e-01 [3,] -0.3333333 0

Octave imread function

纵然是瞬间 提交于 2019-12-04 03:32:31
I installed latest Octave on Ubuntu 14.04 machine. However, when I tried to run imread command, it showed the following error message: octave:12> imread('newfile.png') error: imread: invalid image file: /usr/lib/x86_64-linux-gnu/octave/3.8.1/oct/x86_64-pc-linux-gnu/__magick_read__.oct: failed to load: /usr/lib/x86_64-linux-gnu/octave/3.8.1/oct/x86_64-pc-linux-gnu/__magick_read__.oct: undefined symbol: _ZN6Magick5ColorC1Ehhh error: called from: error: /usr/share/octave/3.8.1/m/image/private/__imread__.m at line 181, column 7 error: /usr/share/octave/3.8.1/m/image/private/imageIO.m at line 66,

MATLAB/Octave: cut a lot of circles from a image

吃可爱长大的小学妹 提交于 2019-12-04 03:28:32
问题 I have an matrix (image) and information about interesting part within circles (center corrdinates and radii given). I want to cut for all the circles the parts of the matrix in order to do some more calculations for each circle. Or at least I want to have a bitmask with all the circle. I use Octave (but could also use MATLAB but it would be difficult because of licence iusses) and have the following script with some hints from stackoverflow. I have information of 20 circles and it takes

Efficient Array Preallocation in MATLAB

依然范特西╮ 提交于 2019-12-04 01:23:57
One of the first things one learns about programming efficiently in MATLAB is to avoid dynamically resizing arrays. The standard example is as follows. N = 1000; % Method 0: Bad clear a for i=1:N a(i) = cos(i); end % Method 1: Better clear a; a = zeros(N,1); for i=1:N a(i) = cos(i) end The 'Bad' variant here requires O( N ^2) time to run, as it must allocate a new array and copy the old values at each iteration of the loop. My own preferred practice when debugging is to allocate an array with NaN , harder to confuse with a valid value than 0 . % Method 2: Easier to Debug clear a; a = NaN(N,1);

How do I declare a symbolic matrix in Octave?

穿精又带淫゛_ 提交于 2019-12-03 22:14:50
In MatLab, you can declare symbols pretty easily: syms a,b mat = [a,b] I'm getting an error, however, when I try to replicate this in Octave. This is the code I'm using: > symbols > a = sym("a") a = a > b = sym("b") b = b > mat = [a,b] error: octave_base_value::resize (): wrong type argument `ex' error: octave_base_value::resize (): wrong type argument `<unknown type>' octave-3.2.3.exe:4:C:\Octave\3.2.3_gcc-4.4.0\bin How do you declare a symbolic matrix in octave? Would this help ? It looks like you might need the symbolic toolbox package , reference here . Dave Goldsmith If you don't already

Creating animation with multiple plots - Octave/Matlab

旧城冷巷雨未停 提交于 2019-12-03 21:39:34
I'm using Octave to write a script that plots a function at different time periods. I was hoping to create an animation of the plots in order to see the changes through time. Is there a way to do this so to possibly save each plot for each time in some way that each plot can be combined to create this animation? Thanks in advance for the advise! This creates an animated gif data=rand(100,100,20); %100 by 100 and 20 frames %data go from 0 to 1, so lets convert to 8 bit unsigned integers for saving data=data*2^8; data=uint8(data); %Write the first frame to a file named animGif.gif imwrite(data(:

How to code a slider in Octave to have interactive plot?

安稳与你 提交于 2019-12-03 20:28:50
my target is to have a plot that shows Stochastic oscillator on forex market, and in order to validate which parameter is the best one to setup it, I would use a slider to modify it and show updated result on plot. I have my historical data, for a defined pair (let say AUDUSD) and after loading it, I calculate Stocastic oscillator: function [stoch, fk, dk] = stochastic(n, k, d) X=csvread("AUDUSD_2017.csv"); C=X(2:length(X),5); L=X(2:length(X),4); H=X(2:length(X),3); O=X(2:length(X),2); for m=n:length(C)-n stoch(m)=((C(m)-min(L(m-n+1:m)))/(max(H(m-n+1:m))-min(L(m-n+1:m))))*100; endfor for m=n

Is the Julia language really as fast as it claims?

我只是一个虾纸丫 提交于 2019-12-03 19:13:15
问题 Following this post I decided to benchmark Julia against GNU Octave and the results were inconsistent with the speed-ups illustrated in julialang.org. I compiled both Julia and GNU Octave with CXXFLAGS='-std=c++11 -O3' , the results I got: GNU Octave a=0.9999; tic;y=a.^(1:10000);toc Elapsed time is 0.000159025 seconds. tic;y=a.^(1:10000);toc Elapsed time is 0.000162125 seconds. tic;y=a.^(1:10000);toc Elapsed time is 0.000159979 seconds. -- tic;y=cumprod(ones(1,10000)*a);toc Elapsed time is 0