【问题标题】:Matlab polyfit for a region of data数据区域的Matlab polyfit
【发布时间】:2018-11-27 15:34:11
【问题描述】:

我有一组数据需要为(一阶polyfit)生成两条线性最佳拟合线,但我不知道如何指定每条线应适合数据的区域。我需要最小 x 值和 0 之间的区域中的一条线,以及 0.25

另外,在第二个区域中,有两个清晰的数据区域,一个在另一个之上,我需要将最佳拟合线仅拟合到较低的区域。

我是 Matlab 的新手,因此非常感谢任何帮助

%load data, force and velocity
load ('exp_6_Force');
load ('exp_6_Velocity');

% Give a name to the title bar.
set(gcf,'name','Experiment 6 velocity','numbertitle','off')

%set variables to x and y 
x = Force; 
y = Velocity;

%plot the graph
plot(x,y);

%add grid and legend
grid on;
legend ('Velocity');

%add labes and title
xlabel ('Force');
ylabel ('Velcoity');

% Enlarge figure to full screen.
set(gcf, 'units','normalized','outerposition',[0 0 1 1]);

%find coordinates of y min point
[value,index1] = min(y);
yminxcoor = x(index1);
yminycoor = y(index1);

【问题讨论】:

  • 在此处查看逻辑索引 (de.mathworks.com/company/newsletters/articles/…)。
  • 对于区域,您是指区域 1 的 x_min
  • @BanghuaZhao 第一个地区是,第二个地区没有。对于第二个区域,我只对紧密分组且 x>0.25 的数据感兴趣。这应该对图像有意义。

标签: matlab graph new-operator


【解决方案1】:

使用logical index 获取两个区域的xy 数据:

对于区域 1:

x_region1 = (x<0).*x
y_region1 = (x<0).*y

对于区域 2:

x_region2 = (x>0.25).*x
y_region2 = (x>0.25).*y

那么你可以在这些地区polyfit

对于区域 1:

p_region1 = polyfit(x_region1, y_region1, 1)

对于区域 2:

p_region2 = polyfit(x_region2, y_region2, 1)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-09-14
    • 2015-08-23
    相关资源
    最近更新 更多