% Description
[num,txt,raw] = xlsread(filename)
% reads data from the first worksheet in the Microsoft Excel spreadsheet file named filename and returns the numeric data in array num. Optionally, returns the text fields in cell array txt, and the unprocessed data (numbers and text) in cell array raw.
[num,txt,raw] = xlsread(filename,sheet)
% reads the specified worksheet.
[num,txt,raw] = xlsread(filename,range)
% reads data from the specified range of the first worksheet in the file. Specify range using the syntax 'C1:C2', where C1 and C2 are two opposing corners that define the region. Supported only on Windows systems with Excel software.
[num,txt,raw] = xlsread(filename,sheet,range)
% reads from the specified sheet and range. Supported only on Windows systems with Excel software.
[num,txt,raw] = xlsread(filename,-1)
%opens an Excel window to interactively select data. Supported only on Windows systems with Excel software.
[num,txt,raw] = xlsread(filename,sheet,'','basic')
%reads data from the spreadsheet in basic mode, the default on systems without Excel software.
[num,txt,raw,custom] = xlsread(filename,sheet,range,'',functionHandle)
%reads from the spreadsheet, executes the function associated with functionHandle on the data, and returns the final results. Optionally, returns additional custom output, which is the second output from the function. xlsread does not change the data stored in the spreadsheet. Supported only on Windows systems with Excel software.
[num,txt,raw] = xlsread(filename)
filename: 要读取得Excel文件路径 单引号括起来的带路径的文件名 num: 函数直接读取filename所指文件的sheet1中的数据区域存储到双精度矩阵num中;其中数据区域的选取规则是对表格前几个含有非数值的行(列)直接忽略,不算入数据区域;另外如果在数据区域中含有非数值的单元,将其处理为nan txt: cell类型的数组,如果第一行有文本信息,将其存储在这个当中 raw: cell类型的数组,sheet1中所有未处理的原始数据
最常用,也是最好用。
[num,txt,raw] = xlsread(filename,sheet,range)
sheet
: 用来指定读入Excel文件的第几个sheet,sheet
取值为大于等于1
的整数range
: 指定一个矩形的区域,用单引号括起来的一个字符串数组。例如:'D3:Y4'
代表以D3和Y4为对角定点的矩形域; 注意: 当Excel中有合并单元格时,任何一个合并前的单元格的名字(比如D3)都会指代整个合并后的单元格,而将整个单元格读入。为了避免不必要的错误,尽量读入表格中合并单元格。
[num,txt,raw] = xlsread(filename,-1)
运行后,Matlab将会打开相应的Excel文件,用鼠标选择需要导入的数据区域,可以切换到想要的sheet
Excel数据如下图所示:
其中从B2
到L3003
的区域都是需要获取的数据,获取完了之后,需要对所有的力矩(Mx,My,Mz
)进行加和操作
获取后工作空间的变量:
%% 获取xls数据
clear all
clc
%% Wx15
filename = 'VT0_To_90_Wx15_AOA4_12_Betax_LRVTWB.xls'; % 该文件就在同一目录下
%% ----AoA4
sheet = 1;
%% ---------B0
readRange = 'B3:L3003'; % 从B3到L3003都是有效数据
[num,txt,raw] = xlsread(filename,sheet,readRange);
wx15_A4_B0_VT = num(:,2);
wx15_A4_B0_Mx = num(:,3) + num(:,6) + num(:,9);
wx15_A4_B0_My = num(:,4) + num(:,7) + num(:,10);
wx15_A4_B0_Mz = num(:,5) + num(:,8) + num(:,11);