在MATLab中从同一个Excel工作表导入两组数据

我正在为一所大学的教授开发一个小型项目,他需要通过MATLAB对数据进行sorting,并对数据进行各种其他操作。 我已阅读的数据没有问题,使用:

filename = 'file.xlsx'; data = xlsread(filename) 

这样它将所有数据导入一个大matrix。 从这里,在文件本身,数据被分成两大类,左膝和右膝。

我的问题是我试图分开数据,但没有运气。 由于这两个集合没有被相等的行分开,我不能使用一个简单的数组来select不同的列。 绿柱设置一个,黄金设置两个。 有没有办法,我可以看看第二行,看看是否是左或右,然后把数据放入不同的方式? 还是有更好的方法呢?

看到你的截图…你已经在左边或右边的膝盖标记在那里的列标题。

但是,xlsread不会提供列标题,只有数字…或者它呢?

从Matlab帮助xlsread :

 [ndata, text, alldata] = xlsread('myExample.xlsx') ndata = 1 2 3 4 5 NaN 7 8 9 text = 'First' 'Second' 'Third' '' '' '' '' '' 'x' alldata = 'First' 'Second' 'Third' [ 1] [ 2] [ 3] [ 4] [ 5] 'x' [ 7] [ 8] [ 9] xlsread returns numeric data in array ndata, text data in cell array text, and unprocessed data in cell array alldata. 

所以,现在你得到了“ndata”,但你也想获得“文本”。 为xlsread设置一个额外的输出参数,你应该得到它。

 [data, text, ~] = xlsread(filename); % the ~ just means throw away that third output 

然后你可以在适当的行上使用strfind或strcmp来拉出“Left”或“Right”。

如果你知道数据被放置在一个特定的范围内,你可以为每一组数据做到这一点:

 filename = 'file.xlsx'; sheet = 1; xlRange = 'B2:C3'; subsetA = xlsread(filename, sheet, xlRange) 

或者你可以阅读一列数据:

 columnB = xlsread(filename,'B:B') 

否则,您应该将数据加载到数据数组之后将数据分开,就像以前一样。