最好用的方法
filename = 'myExample.xlsx';
sheet = 1;
xlRange = 'B2:C3';
[num,txt,raw] = xlsread(filename,sheet,xlRange)
num = xlsread(filename)
num = xlsread(filename,sheet)
num = xlsread(filename,xlRange)
num = xlsread(filename,sheet,xlRange)
[num,txt,raw] = xlsread(___)
___ = xlsread(filename,-1)
[num,txt,raw,custom] = xlsread(filename,sheet,xlRange,'',processFcn)
values = {1, 2, 3 ; 4, 5, 'x' ; 7, 8, 9};
headers = {'First','Second','Third'};
xlswrite('myExample.xlsx',[headers; values]);
filename = 'myExample.xlsx';
A = xlsread(filename)
values = {1, 2, 3 ; 4, 5, 'x' ; 7, 8, 9};
headers = {'First','Second','Third'};
xlswrite('myExample.xlsx',[headers; values]);
filename = 'myExample.xlsx';
sheet = 1;
xlRange = 'B2:C3';
subsetA = xlsread(filename,sheet,xlRange)
values = {1, 2, 3 ; 4, 5, 'x' ; 7, 8, 9};
headers = {'First','Second','Third'};
xlswrite('myExample.xlsx',[headers; values]);
filename = 'myExample.xlsx';
columnB = xlsread(filename,'B:B')
values = {1, 2, 3 ; 4, 5, 'x' ; 7, 8, 9};
headers = {'First','Second','Third'};
xlswrite('myExample.xlsx',[headers; values]);
[num,txt,raw] = xlsread('myExample.xlsx')
function [Data] = setMinMax(Data)
minval = 0.2;
maxval = 0.8;
for k = 1:Data.Count
v = Data.Value{k};
if v > maxval
Data.Value{k} = maxval;
elseif v < minval
Data.Value{k} = minval;
end
end
A = rand(5);
xlswrite('myExample.xlsx',A,'MyData')
trim = xlsread('myExample.xlsx','MyData','','',@setMinMax)
function [Data,indices] = setMinMax(Data)
minval = 0.2;
maxval = 0.8;
indices = [];
for k = 1:Data.Count
v = Data.Value{k};
if v > maxval
Data.Value{k} = maxval;
indices = [indices k];
elseif v < minval
Data.Value{k} = minval;
indices = [indices k];
end
end
%自定义索引输出
[trim,txt,raw,idx] = xlsread('myExample.xlsx',...
'MyData','','',@setMinMax)
字符向量或字符串
示例:‘myFile.xlsx’
char | string
使用两个对角来定义要读取的区域;
输入不区分大小写;
数据类型:char | string
具体用法见上面示例,自定义函数,实现对表格的操作。
返回为double类型的数值矩阵。
返回为元胞数组。
返回工作表中的数值数据和文本数据,数据类型为元胞数组。可以看作上面两个的和。
具体的输出形式,数据类型,什么的都要根据processFcn函数来确定。