如何从excel读取到matlab并使用这些信息来查找一些variables

我有一个包含有关指挥的信息的Excel文件。 例如:

type r GMR R -------- -------- -------- -------- b 0.773 0.604 0.238 c 0.815 0.6614 0.235 d 0.864 0.698 0.209 

我想编写一个Matlab程序来读取这些值,然后显示一条消息“types的指挥? “

然后从所需的行取值,并使用它来查找一些值。 例如:

 If b was chosen i want to find x=ln(r)=ln(.773) and y=GMR^2 ... if c was chosen x=ln(0.815) 

我知道如何编写一个程序,可以从一行或一列读取,而不是整个表格。

使用xlsread

[num,txt,raw] = xlsread(filename)从名为filename的Microsoft Excel电子表格文件中的第一个工作表中读取数据,并返回数组num中的数字数据。 或者,返回单元格数组txt中的文本字段,以及单元格数组raw中的未处理数据(数字和文本)。

[num,txt,raw] = xlsread(filename,sheet)读取指定的工作表。

所以这里有一个示例程序, foo.xls读入数字matrixD和文本信息txt

 %# Read the XLS file [D txt] = xlsread('foo.xls'); %# Assume the columns are fixed (if not see note 3) r_col = 1; gmr_col = 2; %# Get the type of conductor cond = inputdlg('type of conductor?'); %# Search for the right row index = strcmp(txt(2:end,1),cond); %# Compute the data x = log(D(index,r_col)); y = D(index,gmr_col).^2; 

注意:

  1. 如果您不想要对话框,请将inputdlgreplace为input
  2. 如果有多个具有相同type值的行,则xy将是向量
  3. 我假设rGMR分别是第1列和第2列。 如果你不知道这个,你可以通过在txt的第一行使用strcmp来find。 也就是说,

     r_col = strcmp(txt(1,:),'r'); gmr_col = strcmp(txt(1,:),'GMR');