matlab提取Excel数据代码示例

今天用matlab提取了Excel表中指定位置的数据,并画出折线图,用于了解数据的变化情况。

function analysis
%用于提取Excel表中数据
clc;
close all;  % 关闭之前打开的所有figure
alpha = {'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','AA','AB'};
line = {'3','4','5','6','7','8','9','10','11','12','13','14'};
kbps = double(zeros(1,5));
fps = double(zeros(1,5));
ssim = double(zeros(1,5));
psnr = double(zeros(1,5));
%get file_name from excel
[~,txt,~] = xlsread('file.xls','SUB_ME','A3:A14');  %经测,matlab 2015b不能读取后缀为.xlsx的数据,后缀需改为.xls
num = size(txt);
for i = 1:1:num
figure('NumberTitle','off','Name',txt{i});
%get data from excel
for j = 1:5
kbps(j) = xlsread('file.xls','Sheet1',cat(2,alpha{5*j},line{i}));
psnr(j) = xlsread('file.xls','Sheet1',cat(2,alpha{5*j+1},line{i}));
ssim(j) = xlsread('file.xls','Sheet1',cat(2,alpha{5*j+2},line{i}));
fps(j) = xlsread('file.xls','Sheet1',cat(2,alpha{5*j+3},line{i}));
end
%print line chart
x = [1,2,3,4,5];
subplot(2,2,1);plot(x,kbps,'r-');title('kbps');
for j = 1:5
text(x(j),kbps(j),num2str(kbps(j)));
end
subplot(2,2,2);plot(x,fps,'r-');title('fps');
for j = 1:5
text(x(j),fps(j),num2str(fps(j)));
end
subplot(2,2,3);plot(x,ssim,'r-');title('ssim');
for j = 1:5
text(x(j),ssim(j),num2str(ssim(j)));
end
subplot(2,2,4);plot(x,psnr,'r-');title('psnr');
for j = 1:5
text(x(j),psnr(j),num2str(psnr(j)));
end
end
end

效果示意图如下所示:

猜你喜欢

转载自blog.csdn.net/allen_sdz/article/details/85002658
今日推荐