e421.m
来自「matlab算法集 matlab算法集」· M 代码 · 共 31 行
M
31 行
%----------------------------------------------------------------------
% Example 4.2.1: Piecewise-Linear Fit
%----------------------------------------------------------------------
% Initialize
clc
clear
n = 9;
p = 20*n;
x = [0 : 8]';
y = [6 0 2 -1 3 4 -2 5 4]';
X = zeros (p,2);
Y = zeros (p,2);
% Perform fit and plot
fprintf ('Example 4.2.1: Piecewise-Linear Fit\n');
show ('x',x)
show ('y',y)
X(:,1) = linspace(x(1),x(n),p)';
Y(:,1) = interp1 (x,y,X(:,1));
for i = 1 : p
j = min (i,n);
X(i,2) = x(j);
Y(i,2) = y(j);
end
graphxy (X,Y,'Piecewise-Linear Fit','x','y','s');
%----------------------------------------------------------------------
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?