Matlab读取Excel文件相关操作及示例
1 Matlab文件夹相对路径设置
l Cd函数功能:Change current folder
Syntax:
cd(newFolder)
oldFolder = cd(newFolder)
cd
Description
cd(newFolder) changes the current folder to the string
newFolder.
oldFolder = cd(newFolder) returns the existing current
folder as a string to oldFolder, and then changes the
current folder to newFolder.
cd displays the current folder.
The newFolder string can be:
· A full or relative path.
· ../, which indicates one level up from the current
folder.
· Multiple strings of ../, which indicates multiple levels
up from the current folder.
· ./, which indicates a path relative to the current folder,
although without the ./, cd assumes that the path
is relative to the current folder.
l pwd: PWD Show (print) current working
directory.
PWD displays the current working directory.
S = PWD returns the current directory in the string S.
2 文件夹下的文件识别
%%%%%% 读取Excel文件
dirs=dir('c:\*.sys'); %
用你需要的目录以及文件扩展名替换。读取某个目录的指定类型文件列表,返回结构数组。
dircell=struct2cell(dirs)' ; %
结构体(struct)转换成元胞类型(cell),转置一下是让文件名按列排列。
filenames=dircell(:,1) % 第一列是文件名
3 Excel文件读取说明
l 读Excel文件(相关说明:doc xlsread)
l 写Excel文件(相关说明:doc xlswrite)
l 注:在写Excel文件时,每使用一次xlswrite,Excel文件都需要保存一次;若文件比较大,写的速度会很慢。为避免每次保存,可改写系统函数,等所有写的数据写好后,再进行保存,见以下Excel代码:
function
[WriteTime]=MyXlsWrite(FileName,data,SheetNames,range,FileSave)
% % 参考系统函数xlswrite,将数据批处理写入Excel文件中:
% % 主要功能