如何从Excel文件中将所需数据检索到Matlab(R2015 a)中?

时间:2018-12-15 11:07:20

标签: excel matlab

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)似乎输出第一行的值。

任何人都可以解释上述索引的工作原理。

1 个答案:

答案 0 :(得分:0)

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.