首页 > 解决方案 > 如何将所需数据从 excel 文件中检索到 matlab (R2015 a) 中?

问题描述

function sample()
[FileName,FilePath]=uigetfile();
ExPath = [FilePath FileName];
f=xlsread(ExPath); 
[R C]=size(f);
disp(R);
disp(C);
Y=f(R+1:R:R*C);
X=f(2:1:R);
Z=f(2:1:R,2:1:C);
disp(Y);

上面是一个从excel文件中读取数据的示例代码。我不知道索引是如何完成的。

disp(Y) 似乎输出了第一行的值。

谁能解释一下上述索引是如何工作的。

标签: excelmatlab

解决方案


Matlab 按列存储 n 维数组,然后是行,然后是每个更高的维度。

f = [1 2; 3 4]; ' an example
f(1,1); ' returns 1
f(2,1); ' returns 3
f(1,2); ' returns 2
f(2); 'returns 3
f(1,:); ' returns [1 2]
f(2,1:1:2); 'returns [3 4];
f(:,1); 'returns [1; 3]
f(1:1:4); 'returns [1 3 2 4]
f(f>1); 'returns [3 2 4]
f(R+1:R:R*C); 'returns 2 - the first row starting at the 2nd column.

推荐阅读