octave

Iterate over diagonal elements of a Matrix in MatLab

↘锁芯ラ 提交于 2020-01-05 04:25:13
问题 I need to get the indexes of all diagonals in a matrix. The matrix can be non square. The diag function gives the values, but I need the coords. So for instance with this: [1 2 3; 4 5 6; 7 8 9] , I want [1 1; 2 2; 3;3] PLUS [2 6] and 3 because they are the upper diagonals of the matrix, and same for below i.e. [4 8] and 7 . So the full list of indexes is: [1 1; 2 2; 3 3], [1 2; 2 3], [1 3], [2 1], [3 2], [3 1] . And I need this in the other diagonal direction too... And it needs to work for

Using octave to map vector values

折月煮酒 提交于 2020-01-04 15:31:25
问题 Can anyone explain how the following code: Y(Y==0) = -1 sets all values of 0 to -1. For example for: Y = [1 1 1 0 0 0 1] we get: Y = [1 1 1 -1 -1 -1 1] What is confusing me is that Y==0 does not return a vector of indices. An if I try to use the vector Y==0 directly I get the error: Y([0 0 0 1 1 1 0]) = -1 error: subscript indices must be either positive integers or logicals I would have naturally opted for: Y(find(Y==0)) = -1 and would like to know why the above does not use find TIA 回答1:

Inconsistent behavior of builtin when overloading built-in functions in Octave

寵の児 提交于 2020-01-04 02:42:08
问题 I am trying to overload some built-in functions in Octave to perform a custom action prior to calling the built-in version of the overloaded function. In MATLAB (and supposedly Octave), I can do this using the builtin function. The typical function definition would look something like this where I forward all inputs/outputs to/from the built-in after doing my custom action: function varargout = disp(varargin) % Do a custom thing fprintf('Calling overloaded disp!\n') % Now call the builtin

Sort array elements by the frequency of its elements

廉价感情. 提交于 2020-01-04 01:28:07
问题 Is it possible in matlab/octave to use the sort function to sort an array based on the relative frequency of their elements? For example the array m= [4,4,4,10,10,10,4,4,5] should result in this array: [5,10,10,10,4,4,4,4,4] 5 is the less frequent element and is on the top while 4 is the most frequent and it's on bottom. Should one use the indices provided by histcount ? 回答1: The following code first calculates how often each element occurs and then uses runLengthDecode to expand the unique

Cannot load Packages available in share\octave\packages but not listed in share\octave\octave_packages

[亡魂溺海] 提交于 2020-01-03 17:45:44
问题 The short story : In the directory ...\octave-4.2.1\share\octave\packages there were initially 45 package subdirectories (with .m and other files), for instance financial-0.5.0 . But I could not find a way to use them . In more detail : I have unzipped the portable (.zip) version of Octave 4.2.1 64 bit for Windows, at 8:00am (useful info for later), into C:\Users\user1\DOCUME~1\apps\OCTAVE~1.1 (originally C:\Users\user1\Documents\apps\octave-4.2.1 ). I have then installed symbolic-2.6.0 (at 8

Octave - random generate number

十年热恋 提交于 2020-01-03 17:21:09
问题 I have a simple question about randomly generating numbers in Octave/Matlab. How do I randomly generate a (one!) number (that is either 0 or 1)? I could really use an example. Thanx 回答1: Use rand, which generates a uniform pseudo-random number in the range 0..1, and then test this value against a suitable threshold, e.g. 0.5 for equal probability of 1 or 0: r = rand > 0.5 回答2: You should use randi for integer random numbers: randi(2) - 1 回答3: For the sake of variety, here's another way floor

Octave : How to change line color and width in drawRect

只谈情不闲聊 提交于 2020-01-02 22:00:25
问题 :-) Hi, guys. Is there any way to change the line color and width of function drawRect in Octave ? According to its reference, there's no property-value pair to set in this function. Thanks. 回答1: The drawRect function does not accept a property-value pair, but it does return a graphics handle from where you can set any property: r = drawRect (x, y, w, h); set (r, "color", [1 0 0]); # set to red (RGB triplets) set (r, "linewidth", 5); Use get (r) to see a list of all properties, or read the

Octave: Load all files from specific directory

人盡茶涼 提交于 2020-01-02 16:25:21
问题 I used to have Matlab and loaded all txt-files from directory "C:\folder\" into Matlab with the following code: myFolder = 'C:\folder\'; filepattern = fullfile(myFolder, '*.txt'); files = dir(filepattern); for i=1:length(files) eval(['load ' myFolder,files(i).name ' -ascii']); end If C:\folder\ contains A.txt, B.txt, C.txt, I would then have matrices A, B and C in the workspace. The code doesn't work in octave, maybe because of "fullfile"?. Anyway, with the following code I get matrices with

Machine Learning Cocktail Party Audio Application

北城余情 提交于 2020-01-02 09:59:15
问题 I have a question with regards to this post: cocktail party algorithm SVD implementation ... in one line of code? I realize there are similar questions to this. However, please note that my particular question takes things in a new direction, inasmuch that I'm looking for a purely Python equivalent. Is this procedure as elegant/simple when written in Python 3.5 (as opposed to the original Octave 'one line of code')? Also include any relevant Python libraries for this kind of application. Of

Image processing to size bubbles in octave

耗尽温柔 提交于 2020-01-02 08:45:12
问题 Hi I am wondering whether anybody can offer any pointers on a potential approach to sizing the bubbles at the water surface (not those below it) in the following image. I would like to use an open source software if possible (my mind is leaning towards octave given that an image is a matrix). I have absolutely no background in image processing so any ideas are welcome. Obviously as a starting point I know the size of each pixel in the raw image (this image is a compressed version) so