octave

Calculate distance point to line segment with special cases

空扰寡人 提交于 2019-12-02 11:37:52
问题 I need to implement the following logic: Given a set of 2d sample points (given as x-y-coordinate pairs) and a set of line segments (also x-y-coordinate pairs). Edit 1: How to calculate (vectorized) the distance of the points pi to the lines Li ? The points are approximately near the lines and I want to get the distance from each of the sample points to the nearest line segment. The may be points, which are a bit "off" (see p6 in the first picture) and these could be found by the following

Indexing over all values in nested struct

妖精的绣舞 提交于 2019-12-02 09:51:45
I have a nested struct which contains values and is defined as: mystruct.level1.a = 1; mystruct.level1.b = 2; mystruct.level2.a = 8; mystruct.level2.b = 9; I want to perform operations on the elements in level1 and level2. What I want to do is access the values in level1 and level2, put them in a vector, without referencing the nested field names. E.g. I'd like to do something like: level1_vector = [mystruct.level1] Which I would like to output: level1_vector = [1 2] How can I do that? Use the combination of two functions below: cell2mat(struct2cell(mystruct.level1)) There's a structfun to do

How to loop two vectors in MATLAB?

别说谁变了你拦得住时间么 提交于 2019-12-02 09:49:26
问题 In python one can use zip to loop multiple vectors or enumerate to get the current index of the looped vector like so one = ['A', 'B', 'C'] two = [1, 2, 3] for i, j in zip(one, two): print i, j for j, i in enumerate(one): print i, two[j] Gives >>> A 1 B 2 C 3 A 1 B 2 C 3 In MATLAB it's possible to do one = {'A' 'B' 'C'}; two = [1 2 3]; for i = 1:1:length(one) printf('%s %i\n', one{i}, two(i)); endfor j = 1; for i = one printf('%s %i\n', i{1}, two(j)); j = j + 1; endfor giving A 1 B 2 C 3 A 1

Why comparing matrices is not evaluated as boolean in Octave?

若如初见. 提交于 2019-12-02 09:39:34
Im new to Octave and playing around with the console. why when comparing matrices, the expression is not evaluates as boolean : example: >> A=[1,2;3,4]; % creating 2x2 matrix >> 5 == 5 % sample comparison returns true (1) ans = 1 >> A(1,1) == A(1,1) % single element comparison returns true (1) ans = 1 >> A == A % returns 2x2 matrix ??? ans = 1 1 1 1 >> size(A == A) % prove that the above returns 2x2 matrix ans = 2 2 == is for element-wise comparison of two matrices. To check whether two matrices are same or not, use isequal . Sardar's answer is correct, but when it comes to computational time,

Mex file building with Octave (issue with wrappers)

白昼怎懂夜的黑 提交于 2019-12-02 07:57:18
I am currently porting some code from Matlab to Octave. Some of the functions of the Matlab code use the Piotr's Computer Vision Matlab Toolbox ( here ) that includes some mex files. In Matlab, everything is working like a charm but when I run my codes with Octave, it throws this error: error: 'imResampleMex' undefined near line 50 column 5 However all the internal paths within the toolbox should be good. I figured out that the way Matlab and Octave handle mex files is different and tried to build one of the mex files from the C++ function within Octave like this: mkoctfile --mex imResampleMex

solving nonlinear equations in Octave

僤鯓⒐⒋嵵緔 提交于 2019-12-02 07:54:23
问题 I am new to Octave and would like to know how to solve nonlinear equation. Here is an example equation x^4-16x^3+61x^2-22x-12=0 Update: w+x+y+1=3 2w+3x+4y+5=10 w-x+y-1=4 thanks 回答1: Use fzero to get the solution closest to a given x0 (well, not necessarily closest, but the first one found): This should work: x0 = 0; f = @(x) x^4 - 16*x^3 + 61*x^2 - 22*x - 12; fzero(f,x0); ans = 0.76393 Also, you should check out roots, to get all the solutions of a polynomial. x = [1 -16 61 -22 -12]; % The

Error : 'x' undefined

浪子不回头ぞ 提交于 2019-12-02 07:51:05
问题 I got a problem with running Octave function (ODE), I've tried already present solutions for this problem but nothing is working. I've also tried by saving my filename as egzamin.m but it too not worked. Code from octave : function dx=egzamin(x,t) dx=zeros(4,1); b=0; g=9.81; x1=x(1); y1=x(2); Vx=x(3); Vy=x(4); dx(1)=Vx; dx(2)=Vy; dx(3)=-b*Vx*sqrt(Vx.^2+Vy.^2); dx(4)=-b*Vy*sqrt(Vx.^2+Vy.^2)-g; endfunction N=mod(291813,100); x1=0; y1=0; Vx=20+N; Vy=20+N; t=0:0.01:500; sol=lsode("egzamin",[x1,y1

Plot doesn't work in Octave 4.0.0 (Windows 7 64-bit)

℡╲_俬逩灬. 提交于 2019-12-02 07:49:20
问题 I'm trying to get Plot working for Octave Windows 7 (64 bit). Things I have tried: Tried changing the graphics_toolkit to gnuplot or fltk. See Plot window not responding I have tried uninstalling and re-installing Octave. I have tried to install the latest version of gnuplot in the Octave Directory. pkg rebuild -noauto oct2mat (didn't help before or after octave restart) The cursor moves to the next line (without ">>", as if waiting for the command to run), but the figure window doesn't show

Calculate distance point to line segment with special cases

天涯浪子 提交于 2019-12-02 07:17:53
I need to implement the following logic: Given a set of 2d sample points (given as x-y-coordinate pairs) and a set of line segments (also x-y-coordinate pairs). Edit 1: How to calculate (vectorized) the distance of the points pi to the lines Li ? The points are approximately near the lines and I want to get the distance from each of the sample points to the nearest line segment. The may be points, which are a bit "off" (see p6 in the first picture) and these could be found by the following algorithm: Case: The sample points projection to the line segment is "left outside". In this case I need

Plot and fill area enclosed by n lines using Octave\Matlab

浪子不回头ぞ 提交于 2019-12-02 07:11:40
问题 Lets suppose I have n curves, which together enclose some region. How to plot the curves and fill in the region they enclose using Octave/Matlab? Below is example for 3 curves (enclosed area is in black): 回答1: You can use the function fill . See the matlab documentation there: http://www.mathworks.fr/help/techdoc/ref/fill.html 回答2: I used the fill and flipr functions in matlab to shade the area between two curves: fill( [x fliplr(x)], [upper fliplr(lower)], 'c', 'EdgeColor','none'), where x =