octave

Setting transparancy of surface plot on Octave

笑着哭i 提交于 2020-01-02 05:42:05
问题 I am running Octave 3.4.0 and want to create a transparent surface plot. However, I have not been able to do so when messing around with facealpha , edgealpha , alphadata and alphadatamapping . Example code for creating a non-transparent surface: p = peaks(40); f1 = figure(10);clf s1 = surface(p) view(3) xlabel('x');ylabel('y'); hold on;plot3([0 40],[40 0],[-10 10],'k') set(s1,'edgecolor','none') set(s1,'facealpha',0.2) The result of this given in the image below. As you can see, the line

Defining your own probability density function in MATLAB

安稳与你 提交于 2020-01-02 05:04:06
问题 Is it possible to define your own probability density function in MATLAB or Octave and use it for generating random numbers? MATLAB and Octave have default functions like rand, randn built in to draw points at random from a uniform, or normal distributions but there seems to be no documentation of how to define my very own proability density function. 回答1: Sampling from an arbitrary random distribution is not always trivial. For well known distributions there are tricks to implement them and

Use if clause in arrayfun in Octave/Matlab

China☆狼群 提交于 2020-01-02 04:05:15
问题 Is it possible to use "if" in arrayfun like the following in Octave? a = [ 1 2; 3 4]; arrayfun(@(x) if x>=2 1 else 0 end, a) And Octave complains: >>> arrayfun(@(x) if x>=2 1 else 0 end, a) ^ Is if clause allowed in arrayfun? 回答1: In Octave you can't use if/else statements in an inline or anonymous function in the normal way. You can define your function in it's own file or as a subfunction like this: function a = testIf(x) if x>=2 a = 1; else a = 0; end end and call arrayfun like this:

Recursively create a sine wave given a single sine wave value and the period

左心房为你撑大大i 提交于 2020-01-01 19:23:17
问题 I am trying to write a .oct function for Octave that, given a single sine wave value, between -1 and 1, and sine wave period, returns a sine wave vector of period length with the last value in the vector being the given sine wave value. My code so far is: #include <octave/oct.h> #include <octave/dColVector.h> #include <math.h> #define PI 3.14159265 DEFUN_DLD (sinewave_recreate, args, , "args(0) sinewave value, args(1) is period") { octave_value_list retval; double sinewave_value = args(0)

How to generate the first twenty powers of x?

爷,独闯天下 提交于 2019-12-31 07:19:26
问题 So, I've got X, a 300-by-1 vector and I'd like [1, X, X*X, X*X*X, ... , X*X*...*X], a 300-by-twenty matrix. How should I do this? X=[2;1] [X,X.*X,X.*X.*X] ans = 2 4 8 1 1 1 That works, but I can't face typing out the whole thing. Surely I don't have to write a for loop? 回答1: If you want to minimize the number of operations : cumprod(repmat(X(:),1,20),2) %// replace "20" by the maximum exponent you want Benchmarking : for X of size 300x1, maximum exponent 20. I measure time with tic , toc ,

Converting image using matlab / octave from rgb to hsv back to rgb

北城以北 提交于 2019-12-31 05:43:45
问题 I'm trying to convert a color image from rgb to hsv (make changes) then back to rgb. As a test I made this code just to test how to go from rgb to hsv back to rgb but when I view the image it just shows up as black. What am I missing? *PS I'm using octave 3.8.1 which works like matlab Here are the octave 3.8.1 packages I have loaded: >>> pkg list Package Name | Version | Installation directory --------------+---------+----------------------- control *| 2.6.2 | /usr/share/octave/packages

How to vectorize row-wise diagonalization of a matrix

谁说我不能喝 提交于 2019-12-31 02:55:28
问题 I have an n-by-m matrix that I want to convert to a mn-by-m matrix, with each m-by-m block of the result containing the diagonal of each row. For example, if the input is: [1 2; 3 4; 5 6] the output should be: [1 0; 0 2; 3 0; 0 4; 5 0; 0 6] Of course, I don't want to assemble the matrix step by step myself with a for loop. Is there a vectorized and simple way to achieve this? 回答1: For a vectorized way to do this, create the linear indices of the diagonal elements into the resulting matrix,

Load a text file containing both numbers and letters

独自空忆成欢 提交于 2019-12-31 02:50:15
问题 I have a text file that looks like so: A B C 1 2 3 (This is just a minimal example of what I actually have. My actual files are HUGE and vary in number of rows.) I would like to load in this file into Octave. However, the file contains letters, rather than just numbers. When I'm trying to apply the load function, I get errors, and I guess this is because the load function only accepts numbers. What function should I use instead? 回答1: Call fopen, fscanf, and fclose. The format string must be

Splitting string by number of characters matlab

拥有回忆 提交于 2019-12-31 01:46:27
问题 Is there any builtin function in Matlab that cuts string by the number of characters and returns it as a cell array or something. For example if call A = some_function(string, 3): Input: string = '1234567890' Output: A = {'123', '456', '789', '0'} or do I need to use loops? Thanks. 回答1: A little long may be: ns = numel(string); n = 3; A = cellstr(reshape([string repmat(' ',1,ceil(ns/n)*n-ns)],n,[])')' 回答2: An alternative solution, which is slightly more elegant (in my opinion), would be using

vector unpacking for octave

此生再无相见时 提交于 2019-12-30 18:27:52
问题 Octave(/matlab)'s notation for handling multiple return values [a, b] = f(x) suggests that the values returned by f(x) are in a sort of row vector and that Octave supports vector unpacking (like Python's tuple-unpacking). Yet when I put [a, b] = [1, 2] I get error: invalid number of output arguments for constant expression Does octave support vector-unpacking? If so, what's the proper notation? I can't find anything in the documentation 回答1: I don't have Octave to test, but in MATLAB you can