(1)问题分析
从图中摘取数据之后,可以先通过matlab的polyfit函数分别得到二次、三次、四次多项式的最小二乘拟合系数,再通过polyval计算1978年到2021年的人口预测值,从而计算拟合误差,最后通过拟合误差最小的拟合多项式预测2022年的人口数量。PS. 问题中2022年的人口数量有误,根据国家统计局数据,2022年全国人口141175万人。
(2)问题的matlab解决代码
%Load data
data=[1978, 96259, 18.25, 6.25, 12.00, 0;
1979, 97542, 17.82, 6.21, 11.61, 1283;
1980, 98705, 18.21, 6.34, 11.87, 1163;
1981, 100072, 20.91, 6.36, 14.55, 1367;
1982, 101654, 22.28, 6.60, 15.68, 1582;
1983, 103008, 20.19, 6.90, 13.29, 1354;
1984, 104357, 19.90, 6.82, 13.08, 1349;
1985, 105851, 21.04, 6.78, 14.26, 1494;
1986, 107507, 22.43, 6.86, 15.57, 1656;
1987, 109300, 23.33, 6.72, 16.61, 1793;
1988, 111026, 22.37, 6.64, 15.73, 1726;
1989, 112704, 21.58, 6.54, 15.04, 1678;
1990, 114333, 21.06, 6.67, 14.39, 1629;
1991, 115823, 19.68, 6.70, 12.98, 1490;
1992, 117171, 18.24, 6.64, 11.60, 1348;
1993, 118517, 18.09, 6.64, 11.45, 1346;
1994, 119850, 17.70, 6.49, 11.21, 1333;
1995, 121121, 17.12, 6.57, 10.55, 1271;
1996, 122389, 16.98, 6.56, 10.42, 1268;
1997, 123626, 16.57, 6.51, 10.06, 1237;
1998, 124761, 15.64, 6.50, 9.14, 1135;
1999, 125786, 14.64, 6.46, 8.18, 1025;
2000, 126743, 14.03, 6.45, 7.58, 957;
2001, 127627, 13.38, 6.43, 6.95, 884;
2002, 128453, 12.86, 6.41, 6.45, 826;
2003, 129227, 12.41, 6.40, 6.01, 774;
2004, 129988, 12.29, 6.42, 5.87, 761;
2005, 130756, 12.40, 6.51, 5.89, 768;
2006, 131448, 12.09, 6.81, 5.28, 692;
2007, 132129, 12.10, 6.93, 5.17, 681;
2008, 132802, 12.14, 7.06, 5.08, 673;
2009, 133450, 11.95, 7.08, 4.87, 648;
2010, 134091, 11.90, 7.11, 4.79, 641;
2011, 134916, 13.27, 7.14, 6.13, 825;
2012, 135922, 14.57, 7.13, 7.43, 1006;
2013, 136726, 13.03, 7.13, 5.90, 804;
2014, 137646, 13.83, 7.12, 6.71, 920;
2015, 138326, 11.99, 7.07, 4.93, 680;
2016, 139232, 13.57, 7.04, 6.53, 906;
2017, 140011, 12.64, 7.06, 5.58, 779;
2018, 140541, 10.86, 7.08, 3.78, 530;
2019, 141008, 10.41, 7.09, 3.32, 467;
2020, 141212, 8.52, 7.07, 1.45, 204;
2021, 141260, 7.52, 7.18, 0.34, 48];
%Do polynomial fitting
warning off;
p2=polyfit(data(:,1),data(:,2),2);
p3=polyfit(data(:,1),data(:,2),3);
p4=polyfit(data(:,1),data(:,2),4);
warning on;
%Calculate error
p2_predict=polyval(p2,data(:,1));
p3_predict=polyval(p3,data(:,1));
p4_predict=polyval(p4,data(:,1));
p2_error=sum((p2_predict-data(:,2)).^2);
p3_error=sum((p3_predict-data(:,2)).^2);
p4_error=sum((p4_predict-data(:,2)).^2);
fprintf('2次、3次、4次多项式的拟合偏差平方和分别为:%d, %d, %d\n',...
p2_error,p3_error,p4_error);
%Predict the population size of 2022
error_vec=[p2_error,p3_error,p4_error];
[~,min_error_ind]=min(error_vec);
switch min_error_ind
case 1
fprintf('最佳拟合多项式是2次。\n');
population_2022=polyval(p2,2022);
case 2
fprintf('最佳拟合多项式是3次。\n');
population_2022=polyval(p3,2022);
case 3
fprintf('最佳拟合多项式是4次。\n');
population_2022=polyval(p4,2022);
end
fprintf('根据最佳拟合多项式预测的2022年人口数量为:%d万人\n',int32(population_2022));
(3)代码运行结果
你发可以复制的内容吧,这种截图的估计没人会弄。
对不同曝光程度的图像进行均衡化处理
数据代码段
%直方图均衡化
figure;
srcimage=imread('C:\Users\27019\Desktop\机器视觉\图1-2.jpg');
info=imfinfo('C:\Users\27019\Desktop\机器视觉\图1-2.jpg');
subplot(2,3,1);
imshow(srcimage);
title('原灰度图像');
subplot(2,3,2);
imhist(srcimage);
title('灰度直方图');
subplot(2,3,3);
H1=histeq(srcimage);
imhist(H1);
title('直方图均衡化');
subplot(2,3,4);
histeq(H1);
title('均衡化处理后的图像');
figure;
srcimage=imread(‘C:\Users\27019\Desktop\机器视觉\图1-2.jpg’);
info=imfinfo(‘C:\Users\27019\Desktop\机器视觉\图1-2.jpg’);
subplot(2,3,1);
imshow(srcimage);
title(‘原灰度图像’);
subplot(2,3,2);
imhist(srcimage);
title(‘灰度直方图’);
subplot(2,3,3);
H1=histeq(srcimage);
imhist(H1);
title(‘直方图均衡化’);
subplot(2,3,4);
histeq(H1);
title(‘均衡化处理后的图像’);
分别处理以下三幅图像
这三幅图像分别是灰度范围分布较大,过度曝光和欠曝光的图像。
处理结果如下
从图像处理的结果来看,主要分别是:过度曝光的图像的灰度直方图大部分集中在灰度值较高的区域,欠曝光的图像的灰度直方图主要集中在灰度值较低的区域,均衡化处理后的直方图分布较为均匀,且图像的亮度较为适中。经过处理后的图像边缘效果更好,图像的信息更明显,达到了增强图像的效果。
对图像进行去噪声处理
使用不同的方法对图像进行去噪声处理,得出各种处理方法的特点。
%空间域模板卷积
clc
clear all %清屏
b=imread('C:\Users\27019\Desktop\机器视觉\图1-4.jpg'); %导入图像
a1=double(b)/255;
figure;
subplot(5,3,1),imshow(a1);
title('原图像');
Q=ordfilt2(b,6,ones(3,3));%二维统计顺序滤波
subplot(5,3,4),imshow(Q);
title('二维顺序滤波,窗口为3')
Q=ordfilt2(b,6,ones(5,5));%二维统计顺序滤波
subplot(5,3,5),imshow(Q);
title('二维顺序滤波,窗口为5')
Q=ordfilt2(b,6,ones(7,7));%二维统计顺序滤波
subplot(5,3,6),imshow(Q);
title('二维顺序滤波,窗口为7')
m=medfilt2(b,[3,3]);%中值滤波
subplot(5,3,7),imshow(m);
title('中值滤波,窗口为3')
m=medfilt2(b,[5,5]);%中值滤波
subplot(5,3,8),imshow(m);
title('中值滤波,窗口为5')
m=medfilt2(b,[7,7]);%中值滤波
subplot(5,3,9),imshow(m);
title('中值滤波,窗口为7')
x=1/16*[0 1 1 1;1 1 1 1;1 1 1 1;1 1 1 0];
a=filter2(x,a1);%邻域滤波*16
subplot(5,3,10),imshow(a);
title('邻域滤波*16')
x=1/32*[0 1 1 1;1 1 1 1;1 1 1 1;1 1 1 0];
a=filter2(x,a1);%邻域滤波*32
subplot(5,3,11),imshow(a);
title('邻域滤波*32')
h = fspecial('average',[3,3]);
A=filter2(h,a1)
subplot(5,3,13),imshow(A);
title('均值滤波,窗口为3')
h = fspecial('average',[5,5]);
A=filter2(h,a1)
subplot(5,3,14),imshow(A);
title('均值滤波,窗口为5')
h = fspecial('average',[7,7]);
A=filter2(h,a1)
subplot(5,3,15),imshow(A);
title('均值滤波,窗口为7')
%高斯模板
figure;
A=imread('C:\Users\27019\Desktop\机器视觉\图1-4.jpg');
subplot(2,3,1);
imshow(A);
title('原始图像');
p=[3,3];
h=fspecial('gaussian',p);
B1=filter2(h,A)/255;
subplot(2,3,2);
imshow(B1);
title('高斯模板,窗口为3');
p=[5,5];
h=fspecial('gaussian',p);
B2=filter2(h,A)/255;
subplot(2,3,3);
imshow(B2);
title('高斯模板,窗口为5');
p=[7,7];
h=fspecial('gaussian',p);
B3=filter2(h,A)/255;
subplot(2,3,4);
imshow(B3);
title('高斯模板,窗口为7');
%均值模板
figure;
A=imread('C:\Users\27019\Desktop\机器视觉\图1-4.jpg');
subplot(2,3,1);
imshow(A);
title('原始图像');
B1=filter2(fspecial('average',3),A)/255;
subplot(2,3,2);
imshow(B1);
title('均值滤波,窗口为3');
B2=filter2(fspecial('average',5),A)/255;
subplot(2,3,3);
imshow(B2);
title('均值滤波,窗口为5');
B3=filter2(fspecial('average',7),A)/255;
subplot(2,3,4);
imshow(B3);
title('均值滤波,窗口为7');
%中值模板
figure;
A=imread('C:\Users\27019\Desktop\机器视觉\图1-4.jpg');
subplot(2,3,1);
imshow(A);
title('原始图像');
B0=medfilt2(A);
subplot(2,3,2);
imshow(B0);
title('中值滤波,窗口为[3,3]');
p=[5,5];
B1=medfilt2(A,p);
subplot(2,3,3);
imshow(B1);
title('中值滤波,窗口为[5,5]');
p=[7,7];
B2=medfilt2(A,p);
subplot(2,3,4);
imshow(B2);
title('中值滤波,窗口为[7,7]');
%空间域模板卷积
clc
clear all %清屏
b=imread(‘C:\Users\27019\Desktop\机器视觉\图1-4.jpg’); %导入图像
a1=double(b)/255;
figure;
subplot(5,3,1),imshow(a1);
title(‘原图像’);
Q=ordfilt2(b,6,ones(3,3));%二维统计顺序滤波
subplot(5,3,4),imshow(Q);
title(‘二维顺序滤波,窗口为3’)
Q=ordfilt2(b,6,ones(5,5));%二维统计顺序滤波
subplot(5,3,5),imshow(Q);
title(‘二维顺序滤波,窗口为5’)
Q=ordfilt2(b,6,ones(7,7));%二维统计顺序滤波
subplot(5,3,6),imshow(Q);
title(‘二维顺序滤波,窗口为7’)
m=medfilt2(b,[3,3]);%中值滤波
subplot(5,3,7),imshow(m);
title(‘中值滤波,窗口为3’)
m=medfilt2(b,[5,5]);%中值滤波
subplot(5,3,8),imshow(m);
title(‘中值滤波,窗口为5’)
m=medfilt2(b,[7,7]);%中值滤波
subplot(5,3,9),imshow(m);
title(‘中值滤波,窗口为7’)
x=1/16*[0 1 1 1;1 1 1 1;1 1 1 1;1 1 1 0];
a=filter2(x,a1);%邻域滤波16
subplot(5,3,10),imshow(a);
title('邻域滤波16’)
x=1/32*[0 1 1 1;1 1 1 1;1 1 1 1;1 1 1 0];
a=filter2(x,a1);%邻域滤波32
subplot(5,3,11),imshow(a);
title('邻域滤波32’)
h = fspecial(‘average’,[3,3]);
A=filter2(h,a1)
subplot(5,3,13),imshow(A);
title(‘均值滤波,窗口为3’)
h = fspecial(‘average’,[5,5]);
A=filter2(h,a1)
subplot(5,3,14),imshow(A);
title(‘均值滤波,窗口为5’)
h = fspecial(‘average’,[7,7]);
A=filter2(h,a1)
subplot(5,3,15),imshow(A);
title(‘均值滤波,窗口为7’)
%高斯模板
figure;
A=imread(‘C:\Users\27019\Desktop\机器视觉\图1-4.jpg’);
subplot(2,3,1);
imshow(A);
title(‘原始图像’);
p=[3,3];
h=fspecial(‘gaussian’,p);
B1=filter2(h,A)/255;
subplot(2,3,2);
imshow(B1);
title(‘高斯模板,窗口为3’);
p=[5,5];
h=fspecial(‘gaussian’,p);
B2=filter2(h,A)/255;
subplot(2,3,3);
imshow(B2);
title(‘高斯模板,窗口为5’);
p=[7,7];
h=fspecial(‘gaussian’,p);
B3=filter2(h,A)/255;
subplot(2,3,4);
imshow(B3);
title(‘高斯模板,窗口为7’);
%均值模板
figure;
A=imread(‘C:\Users\27019\Desktop\机器视觉\图1-4.jpg’);
subplot(2,3,1);
imshow(A);
title(‘原始图像’);
B1=filter2(fspecial(‘average’,3),A)/255;
subplot(2,3,2);
imshow(B1);
title(‘均值滤波,窗口为3’);
B2=filter2(fspecial(‘average’,5),A)/255;
subplot(2,3,3);
imshow(B2);
title(‘均值滤波,窗口为5’);
B3=filter2(fspecial(‘average’,7),A)/255;
subplot(2,3,4);
imshow(B3);
title(‘均值滤波,窗口为7’);
%中值模板
figure;
A=imread(‘C:\Users\27019\Desktop\机器视觉\图1-4.jpg’);
subplot(2,3,1);
imshow(A);
title(‘原始图像’);
B0=medfilt2(A);
subplot(2,3,2);
imshow(B0);
title(‘中值滤波,窗口为[3,3]’);
p=[5,5];
B1=medfilt2(A,p);
subplot(2,3,3);
imshow(B1);
title(‘中值滤波,窗口为[5,5]’);
p=[7,7];
B2=medfilt2(A,p);
subplot(2,3,4);
imshow(B2);
title(‘中值滤波,窗口为[7,7]’);
处理结果如下
高斯滤波器模型
使用高斯模板滤波得到的图像相比原图像更为清晰,达到了去除噪声的效果。同时当高斯模板的窗口越大,得到的图像会越模糊。
中值滤波方法,窗口为3,5,7
中值滤波原理是使用邻域的中值来代替像素原来的值,得到的图像比较清晰。但是使用的中值滤波方法的窗口越大所得到的图像会越模糊。
均值滤波方法,窗口为3,5,7
均值滤波可以看出对颗粒的噪声有很好的过滤作用,采用的是使用邻域的均值代替该像素的值。在均值滤波的方法种,窗口越大得到的图像越模糊。
以下几种处理方式在后方处理中重复试用,此处避免累述,只显示结果,分析特点,避免累述
巴特沃斯滤波器模型
sobel模板
Sobel模板水平和竖直方向上的去噪作用均能达到获取图像的边缘的作用。
Prewitt模板
Prewitt得到的图像都有突出图像边缘的作用。
图像去噪声结果分析
回答:
获取内圆,计算距离
图中一个I-kid机器人A在足球场上拍摄到另一个I-kid机器人B的图片。请首先利用特征提取算法提取地面半径为4.37m的内圆边缘,然后利用所学的摄像机投影模型求解此刻机器人A距离内圆圆心的距离||OA||。(假设机器人A的摄像机被垂直安装,光心位于机器人的中心线上,且其光心距离球场地面为0.5m;同时摄像机的分辨率为640*480像素,主点在其图像中心;摄像机的横向有效焦距为300像素,纵向有效焦距有1200像素)
%Prewitt模板
figure;
A=imread('C:\Users\27019\Desktop\机器视觉\图2.jpg');
subplot(2,3,1);
imshow(A);
title('原始图像');
h=[1 1 1;0 0 0;-1 -1 -1];
B1=filter2(h,A)/255;
subplot(2,3,2);
imshow(B1);
title('Prewitt模板,水平方向');
h=[1 0 -1;1 0 -1;1 0 -1];
B2=filter2(h,A)/255;
subplot(2,3,3)
imshow(B2);
title('Prewitt模板,垂直方向');
%Sobel模板
A=imread('C:\Users\27019\Desktop\机器视觉\图2.jpg');
subplot(2,3,1);
imshow(A);
title('原始图像');
h=[1 2 1;0 0 0;-1 -2 -1];
B1=filter2(h,A)/255;
subplot(2,3,2);
imshow(B1);
title('Prewitt模板,水平方向');
h=[1 0 -1;2 0 -2;1 0 -1];
B2=filter2(h,A)/255;
subplot(2,3,3)
imshow(B2);
title('Prewitt模板,垂直方向');
%低通滤波器
a=imread('C:\Users\27019\Desktop\机器视觉\图1-4.jpg');%读入图像
figure;
subplot(2,4,1);
imshow(a);
z=double(a)/255;
b=fft2(double(a));%对图片进行傅里叶变换
c=log(1+abs(b));
d=fftshift(b);%将变换的原点调整到频率矩阵的中心
e=log(1+abs(d));
%代入巴特沃斯公式进行滤波处理
[m,n]=size(d);
for i=1:256
for j=1:256
d1(i,j)=(1/(1+((i-128)^2+(j-128)^2)^0.5/500)^2)*d(i,j);%截至频率
end;
end;
for i=1:256
for j=1:256
d2(i,j)=(1/(1+((i-128)^2+(j-128)^2)^0.5/1000)^2)*d(i,j);
end;
end;
for i=1:256
for j=1:256
d3(i,j)=(1/(1+((i-128)^2+(j-128)^2)^0.5/2000)^2)*d(i,j);
end;
end;
for i=1:256
for j=1:256
d4(i,j)=(1/(1+((i-128)^2+(j-128)^2)^0.5/4000)^2)*d(i,j);
end;
end;
FF1=ifftshift(d1);
FF2=ifftshift(d2);
FF3=ifftshift(d3);
FF4=ifftshift(d4);
ff1=real(ifft2(FF1));%取傅里叶反变换
ff2=real(ifft2(FF2));
ff3=real(ifft2(FF3));
ff4=real(ifft2(FF4));
subplot(2,4,5);imshow(uint8(ff1));xlabel('截止频率为500');
subplot(2,4,6);imshow(uint8(ff2));xlabel('截止频率为1000');
subplot(2,4,7);imshow(uint8(ff3));xlabel('截止频率为2000');
subplot(2,4,8);imshow(uint8(ff4));xlabel('截止频率为4000');
%不同算子
clear;clc;
close all;
I=imread('C:\Users\27019\Desktop\机器视觉\图2.jpg');
imshow(I,[]);
title('Original Image');
sobelBW=edge(I,'sobel');
figure;
imshow(sobelBW);
title('Sobel Edge');
robertsBW=edge(I,'roberts');
figure;
imshow(robertsBW);
title('Roberts Edge');
prewittBW=edge(I,'prewitt');
figure;
imshow(prewittBW);
title('Prewitt Edge');
logBW=edge(I,'log');
figure;
imshow(logBW);
title('Laplasian of Gaussian Edge');
cannyBW=edge(I,'canny');
figure;
imshow(cannyBW);
title('Canny Edge');
%标记内圆
img=imread('C:\Users\27019\Desktop\机器视觉\图2.jpg');%读取原图
i=img;
img=im2bw(img); %二值化
[B,L]=bwboundaries(img);
[L,N]=bwlabel(img);
img_rgb=label2rgb(L,'hsv',[.5 .5 .5],'shuffle');
imshow(i);
title('end result')
hold on;
k = 109;
boundary = B{k};
plot(boundary(:,2),boundary(:,1),'y','LineWidth',1);%显示内圆标记线
%Prewitt模板
figure;
A=imread(‘C:\Users\27019\Desktop\机器视觉\图2.jpg’);
subplot(2,3,1);
imshow(A);
title(‘原始图像’);
h=[1 1 1;0 0 0;-1 -1 -1];
B1=filter2(h,A)/255;
subplot(2,3,2);
imshow(B1);
title(‘Prewitt模板,水平方向’);
h=[1 0 -1;1 0 -1;1 0 -1];
B2=filter2(h,A)/255;
subplot(2,3,3)
imshow(B2);
title(‘Prewitt模板,垂直方向’);
%Sobel模板
A=imread(‘C:\Users\27019\Desktop\机器视觉\图2.jpg’);
subplot(2,3,1);
imshow(A);
title(‘原始图像’);
h=[1 2 1;0 0 0;-1 -2 -1];
B1=filter2(h,A)/255;
subplot(2,3,2);
imshow(B1);
title(‘Prewitt模板,水平方向’);
h=[1 0 -1;2 0 -2;1 0 -1];
B2=filter2(h,A)/255;
subplot(2,3,3)
imshow(B2);
title(‘Prewitt模板,垂直方向’);
%低通滤波器
a=imread(‘C:\Users\27019\Desktop\机器视觉\图1-4.jpg’);%读入图像
figure;
subplot(2,4,1);
imshow(a);
z=double(a)/255;
b=fft2(double(a));%对图片进行傅里叶变换
c=log(1+abs(b));
d=fftshift(b);%将变换的原点调整到频率矩阵的中心
e=log(1+abs(d));
%代入巴特沃斯公式进行滤波处理
[m,n]=size(d);
for i=1:256
for j=1:256
d1(i,j)=(1/(1+((i-128)2+(j-128)2)0.5/500)2)*d(i,j);%截至频率
end;
end;
for i=1:256
for j=1:256
d2(i,j)=(1/(1+((i-128)2+(j-128)2)0.5/1000)2)*d(i,j);
end;
end;
for i=1:256
for j=1:256
d3(i,j)=(1/(1+((i-128)2+(j-128)2)0.5/2000)2)*d(i,j);
end;
end;
for i=1:256
for j=1:256
d4(i,j)=(1/(1+((i-128)2+(j-128)2)0.5/4000)2)*d(i,j);
end;
end;
FF1=ifftshift(d1);
FF2=ifftshift(d2);
FF3=ifftshift(d3);
FF4=ifftshift(d4);
ff1=real(ifft2(FF1));%取傅里叶反变换
ff2=real(ifft2(FF2));
ff3=real(ifft2(FF3));
ff4=real(ifft2(FF4));
subplot(2,4,5);imshow(uint8(ff1));xlabel(‘截止频率为500’);
subplot(2,4,6);imshow(uint8(ff2));xlabel(‘截止频率为1000’);
subplot(2,4,7);imshow(uint8(ff3));xlabel(‘截止频率为2000’);
subplot(2,4,8);imshow(uint8(ff4));xlabel(‘截止频率为4000’);
%不同算子
clear;clc;
close all;
I=imread(‘C:\Users\27019\Desktop\机器视觉\图2.jpg’);
imshow(I,[]);
title(‘Original Image’);
sobelBW=edge(I,‘sobel’);
figure;
imshow(sobelBW);
title(‘Sobel Edge’);
robertsBW=edge(I,‘roberts’);
figure;
imshow(robertsBW);
title(‘Roberts Edge’);
prewittBW=edge(I,‘prewitt’);
figure;
imshow(prewittBW);
title(‘Prewitt Edge’);
logBW=edge(I,‘log’);
figure;
imshow(logBW);
title(‘Laplasian of Gaussian Edge’);
cannyBW=edge(I,‘canny’);
figure;
imshow(cannyBW);
title(‘Canny Edge’);
%标记内圆
img=imread(‘C:\Users\27019\Desktop\机器视觉\图2.jpg’);%读取原图
i=img;
img=im2bw(img); %二值化
[B,L]=bwboundaries(img);
[L,N]=bwlabel(img);
img_rgb=label2rgb(L,‘hsv’,[.5 .5 .5],‘shuffle’);
imshow(i);
title(‘end result’)
hold on;
k = 109;
boundary = B{k};
plot(boundary(:,2),boundary(:,1),‘y’,‘LineWidth’,1);%显示内圆标记线
处理结果在这里我只做到了标记内圈,计算距离我没能实现,日后实现在评论区补充
结果分析
回答:
以下答案由GPT-3.5大模型与博主波罗歌共同编写:
这里提供一种常见的数据拟合方法——多项式拟合进行人口数量预测,并提供 MATLAB 代码实现。
根据题目给出的图形,我们需要先将数据导入 MATLAB 中。这里使用导入工具将数据保存为名为 population.csv 的文件。代码如下:
% 清空工作区变量
clear all;
% 导入数据
filename = 'population.csv';
delimiter = ',';
startRow = 2;
formatSpec = '%f%f%[^\n\r]';
fileID = fopen(filename,'r');
dataArray = textscan(fileID, formatSpec, 'Delimiter', delimiter, 'HeaderLines' ,startRow-1, 'ReturnOnError', false);
fclose(fileID);
year = dataArray{:, 1};
popu = dataArray{:, 2};
clearvars filename delimiter startRow formatSpec fileID dataArray ans;
将导入的人口数据先绘制到图像上,以便更好的观察数据特点。代码如下:
% 数据绘制
plot(year, popu, '-o');
xlabel('Year');
ylabel('Population');
title('Population Data');
绘制出的图像如下所示:
![image](https://n/