matlab提取Excel資料程式碼示例
阿新 • • 發佈:2018-12-14
今天用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
效果示意圖如下所示: