Excel 在Matlab中查找xlsx行的特定列表
有人能帮我在Matlab中从Excel表格中查找特定列吗?我的文件看起来有点像这样:Excel 在Matlab中查找xlsx行的特定列表,excel,matlab,Excel,Matlab,有人能帮我在Matlab中从Excel表格中查找特定列吗?我的文件看起来有点像这样: % First set of data x y 1 2 2 4 3 6 4 8 5 10 6 12 7 14 8 16 9 18 10 20 % Second set of data % Empty line 1 1.5 2 3 3 4.5 4 6 5 7.5 6 9 7 10.5 8 12 9 13.5 10 15
% First set of data
x y
1 2
2 4
3 6
4 8
5 10
6 12
7 14
8 16
9 18
10 20
% Second set of data
% Empty line
1 1.5
2 3
3 4.5
4 6
5 7.5
6 9
7 10.5
8 12
9 13.5
10 15
% Third set of data
% Empty line
1 0.5
2 1
3 1.5
4 2
5 2.5
6 3
7 3.5
8 4
9 4.5
10 5
我想要Matlab做的是找到:
-对于每组数据(单独),找到该数据并绘制在同一图中
所以我希望Matlab在空行之后自动找到新的集合。目前我的一个问题是,一个数据集使用大约1500行,而下一个数据集则稍微小一些。因此,我可以想象使用类似于:
x=xlsread('Filename.xlsx','A1:AN');
您可以试试这个: 我假设所有数据集之间没有任何空行,而每组数据后面只有一条空行
%// read all set of data
%// you might additionally add range if you want to avoid non-numeric data such as string
a = xlsread('Book1.xlsx');
%// add NaN values at the end if not already present
if ~isnan(a(end,1))
a(end+1,:)=nan;
end
%// detect NaN rows
idx2=find(isnan(a(:,1)));
%// detect start rows for each set of data
idx1=[1 idx2(1:end-1)+1];
%// find number of data sets
n=numel(idx1);
%// create corresponding cell array
out=cell(n,1);
%// put each set of data inside a cell
for k=1:n
out{k}=a(idx1(k):idx2(k)-1,:);
end
%// plot each set of data separately
%// using 'hold all' instead of 'hold on' gives different colors for each data set
hold all
cellfun(@(x) plot(x(:,1),x(:,2)),out);
hold off