⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 xclreadr.m

📁 PLS_Toolbox是用于故障检测与诊断方面的matlab工具箱
💻 M
字号:
function out = xclreadr(file,delim)%XCLREADR Reads ASCII flat files from MS Excel and other spreadsheets%  This function reads tab, space, comma, semicolon or bar delimited%  files with names on the columns (variables) and rows (samples).%  Input is the file name (file), and an optional delimiter character.%  The output is a structure array with date, time, info (data from cell (1,1))%  the variable names (vars), sample names (samps), and data%  matrix (data). If xlreadr is called with no input, or an empty matrix%  for file name, a dialog box allows the user to select the file from%  the hard disk. %%I/O: out = xclreadr(file,delim);%%   Supported delimiters include:%   'tab' or sprintf('\t')%   'space' or ' '%   'comma' or ','%   'semi'  or ';'%   'bar'   or '|'%%See also: AREADR1, AREADR2, AREADR3, AREADR4, XCLGETDATA, XLGETRANGE (Mac)%Copyright Eigenvector Research, Inc. 1998-2000%Modified BMW 11/2000if nargin == 0 | isempty(file)  [file,pathname] = uigetfile('*.*');  file = [pathname,file];endif file == 0  breakend[fid,message] = fopen(file,'r');if fid<0  disp(message)else   if nargin < 2     delim = sprintf('\t');   elseif strcmp(delim,'tab')     delim = sprintf('\t');   elseif strcmp(delim,'space')     delim = ' ';   elseif strcmp(delim,'comma')     delim = ',';   elseif strcmp(delim,'semi')     delim = ';';   elseif strcmp(delim,'bar')     delim = '|';   end   line = fgets(fid);   z = find(line==delim);   nvars = length(z);   if z(1) ~= 1      info = line(1:z(1)-1);   else      info = [];   end   vars = line(z(1)+1:z(2)-1);   for i = 2:nvars-1      vars = strvcat(vars,line(z(i)+1:z(i+1)-1));   end   vars = strvcat(vars,line(z(nvars)+1:end));   out = struct('date',date,'time',clock,'info',info,'vars',vars);   eofflag = 0;   samps = [];   data = [];   while eofflag == 0      line = fgets(fid);      if line ~= -1         z = find(line==delim);		 % If delimiter is last character, missing value at end		 if z(end) == length(line)-1		   line = [line(1:end-1),'NaN',line(end)];		 end         if z(1)~=1            samps = strvcat(samps,line(1:z(1)-1));         else            samps = strvcat(samps,' ');         end         zz = findstr(line,[delim delim]);         if length(zz)>0            for i = 1:length(zz);               line = [line(1:zz(end+1-i)) 'NaN' line(zz(end+1-i)+1:end)];            end         end         data = [data; str2num(line(z(1)+1:end))];      else         eofflag = -1;      end   end   out.samps = samps;   out.data = data;   fclose(fid);end

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -