下面推荐的十字路口功能对于数组达到8000个值非常适用,但如果我有一个100000个或更多数值的数组,我会耗尽内存(和I有16g内存),这很可能是由于具有交集函数的repmat命令引起的。如何找到从阵列创建线条时的交点
我试图找到从数组创建的线的交点。但不断收到错误“fzero:不是一个有效的初始包围”我正在使用八度3.8.1(这是一个开放源代码版本的matlab)下面的图片是我想用黑色在交点处圈。 我是否需要在for循环中使用fzero来遍历x和y值的数组?
clear all,clf, clc,tic
%freq array here
x1=[20,30,40,50,60,70,80]';
x2=[20,30,40,50,60,70,80]';
y1=[2,4,3,7,1,8,4]';
y2=abs(y1-max(y1)); %used to switch high and low amplitude of freq
%fit linear polynomial
p1 = polyfit(x1,y1,1);
p2 = polyfit(x2,y2,1);
%calculate intersection
x_intersect = fzero(@(x) polyval(p1-p2,x),3);
y_intersect = polyval(p1,x_intersect);
line(x1,y1);
hold on;
line(x2,y2);
plot(x_intersect,y_intersect,'r*')
交点运作建议采取以下为数组高达8000个值伟大的工作,但如果我有10万个值的数组或更多我会耗尽内存,(我有RAM的16gig)这个最有可能是由于具有交叉函数的repmat命令引起的。
So now I'm trying to:
1) cycle though each row in the array which represents a line
linea1-6 xvalues = 20 to 30, 30 to 40, 40 to 50, 50 to 60, 60 to 70, 70 to 80
linea1-6 yvalues =2 to 4, 4 to 3, 3 to 7, 7 to 1, 1 to 8, 8 to 4
lineb1-6 xvalues = 20 to 30, 30 to 40, 40 to 50, 50 to 60, 60 to 70, 70 to 80
lineb1-6 yvalues =6 to 4, 4 to 5, 5 to 1, 1 to 7, 7 to 0, 0 to 4
**I'm having problems coding the for loop to work with polyfit and fzero**
2) store the intersection values found for each line into an array.
This should solve running out of memory issues when using large arrays
我不熟悉你使用的语言;不过,在声明x1,x2和y1的行末尾有单引号。也许这与你的问题有关? – Bobort 2014-09-26 14:47:06
@Ander Biguri不,它不是重复的,请阅读更新的问题原始答案不适用于大型数组。 – 2014-09-26 15:29:46
我认为这将有助于如果你能更好地描述你的输入数据。 X2总是等于x1,并且它们是等间隔和单调的吗?仅在您的示例中,y2 = abs(y1-max(y1))。如果我们能够做出这些假设,这将大大简化计算。在这种情况下不需要fzero或polyval。 – Andy 2014-09-28 14:51:22