⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lineintersect.m

📁 determines the intersection points of curves
💻 M
字号:
function [x y signs] = lineIntersect(a, b) 
% Finds the points of intersection for linear time series data
% 'a' and 'b' are linear time series data, 'x' and 'y' are the x and y co-ords for
% the intersections, and 'signs' are the the signs for each point (sign(a-b))
global signs

%% Create Signs
signs = sign(a-b); % when there's a change of signs, there is a cross over...

if (mod(size(signs,1),2) > 0)
    signs2 = [2; signs(1:end,:)];
    signs = [signs; 2]; % If there is an odd number of elements, a 2 is added 
                        % (the 2 ensures that it'll never be seen as an intersection point)
else
    signs2 = [2; signs(1:end-1,:)]; % The same sign matrix, but one value accross (see test2 for reasoning)
end


%% Test for sign changes
test1 = reshape(signs,2,round(size(signs,1)/2)); % Creates a test matrix, reshaped to compare values 1&2 and 3&4 etc...
test2 = reshape(signs2,2,round(size(signs2,1)/2)); % Creates a test matrix, reshaped to compare values 2&3 and 4&5 etc...

% Find all the places where signs changed
test1 = test1(1,:)+test1(2,:);
test2 = test2(1,:)+test2(2,:);
result1 = test1==0 ;
result2 = test2==0;

%% Find vales where signs changed

positions = [find(result1)*2-1 find(result2)*2-2]; % Finds the position of the number before the sign change
x = []; y= [];

a1 = a(positions);
a2 = a(positions+1);
b1 = b(positions);
b2 = b(positions+1);

aa = abs(a1-b1);
bb = abs(a2-b2);

prop = abs(aa./(aa+bb)); % It just works... ;) Using basic geometry... Z's between // lines..
                          % It basically figures out a proportion of the
                          % distance between hights (applies to height and width)

x=prop+positions'; % Calculates the x values using the proportions
y=-prop.*(a1-a2)+a1; % Calculates the y values using the proportions

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -