octave

vector unpacking for octave

ⅰ亾dé卋堺 提交于 2019-12-30 18:27:04
问题 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

Matlab - save(int2str(i), x) doesn't work - Argument must contain a string

倖福魔咒の 提交于 2019-12-30 17:48:00
问题 I have a loop which is generating some data and in certain cases I want to save the data. Therefore I have: save(int2str(i), x); This doesn't work and comes out with the message: ??? Error using ==> save Argument must contain a string. What am I doing wrong? 回答1: The x has to be 'x': save(int2str(i), 'x'); 回答2: Both the filename (in your case you correctly convert what I'm guessing is the loop index, i to a string) and the names of the variables that you want to save must be strings. You can

ignoring return value syntax?

血红的双手。 提交于 2019-12-30 10:05:35
问题 In Matlab, the tilda symbol can be used to ignore a certain parameter from a function that returns multiple parameters. However, when I try the same code in Octave, I get a syntax error. I have two questions: Why does Octave not support this? (i.e. bug, future enhancement, design decision, etc.) What's the alternative syntax in Octave, if any (without just putting a "dummy variable" into the spot then clearing that variable)? Additionally, is this alternative syntax Matlab compatible? % this

Matlab/Octave 1-of-K representation

一世执手 提交于 2019-12-30 06:33:09
问题 I have a y of size 5000,1 (matrix), which contains integers between 1 and 10. I want to expand those indices into a 1-of-10 vector. I.e., y contains 1,2,3... and I want it to "expand" to: 1 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 What is the best way to do that? I tried: Y = zeros(5000,10); Y(y) = 1; but it didn't work. It works for vectors though: if y = [2 5 7] , and Y = zeros(1,10) , then Y(y) = [0 1 0 0 1 0 1 0 0 0] . 回答1: n=5 Y = ceil(10*rand(n,1)) Yexp = zeros(n,10);

how to replace Inf and NaN with zero using built in function

放肆的年华 提交于 2019-12-30 05:55:27
问题 In octave, is there a build in function for replacing Inf/NaN to 0 in a vector For example a = log10([30 40 0 60]) => [1.4771 1.6021 -Inf 1.7782] I can use finite or find function to find the index/position of the valid values but I don't know how to copy the values correctly without writing a function. finite(a) => [1 1 0 1] 回答1: >> a = log10([30 40 0 60]) a = 1.477 1.602 -Inf 1.778 >> a(~isfinite(a))=0 a = 1.477 1.602 0 1.778 does the trick, this uses logical indexing ~ is the NOT operator

Octave - How to install packages on Windows

浪子不回头ぞ 提交于 2019-12-30 05:11:11
问题 Question Due to the issue in Fix for Octave urlread causing Peer certificate cannot be authenticated with given CA certificates, I cannot install Octave packages on Windows. Please suggest other ways to install. Particularly I would like to go through Gradients, Gradient Plots and Tangent Planes which requires Symbolic package. 回答1: EDIT: this bug is no longer present in Octave v4.2.1, and the issue described in the Question should no longer occur. Yes, there appears to be a known issue

How to output matrix dimensions together with its content?

自闭症网瘾萝莉.ら 提交于 2019-12-30 04:02:57
问题 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 回答1: 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',

Computing object statistics from the second central moments

巧了我就是萌 提交于 2019-12-29 07:43:32
问题 I'm currently working on writing a version of the MATLAB RegionProps function for GNU Octave. I have most of it implemented, but I'm still struggling with the implementation of a few parts. I had previously asked about the second central moments of a region. This was helpful theoretically, but I'm having trouble actually implementing the suggestions. I get results wildly different from MATLAB's (or common sense for that matter) and really don't understand why. Consider this test image: We can

Cannot use Octave 4.0.0 graphics toolkit functions under Windows 10

守給你的承諾、 提交于 2019-12-29 06:44:07
问题 I'm using Octave 4.0.0 on a fresh Windows 10 installation and the graphics toolkit related functions (such as plot() or hist() ) are simply not working. plot() creates a new window that freezes immediately in the GUI and no windows at all in the CLI (Octave crashes in both cases). I made sure that graphics_toolkit() was set to "gnuplot" and not "fltk" , but I did not see any improvment. Any suggestion? 回答1: The first time you use plot , imagesc , or something else that uses plotting functions

Why does Gnu Octave have negative zeroes?

风流意气都作罢 提交于 2019-12-29 05:02:06
问题 This is an odd one I'm puzzled about. I recently noticed at the Gnu Octave prompt, it's possible to enter in negative zeroes, like so: octave:2> abomination = -0 And it remembers it, too: octave:3> abomination abomination = -0 In the interest of sanity, negative zero does equal regular zero. But I also noticed that the sign has some other effects. Like these: octave:6> 4 * 0 ans = 0 octave:7> 4 * -0 ans = -0 octave:8> 4 / 0 warning: division by zero ans = Inf octave:9> 4 / -0 warning: