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

标签 excel matlab

我有一个包含导体信息的 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 程序来读取这些值,然后显示一条消息'导体类型? '

然后从所需行中获取值并使用它来查找一些值。
例如:
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) reads data from the first worksheet in the Microsoft Excel spreadsheet file named filename and returns the numeric data in array num. Optionally, returns the text fields in cell array txt, and the unprocessed data (numbers and text) in cell array raw.

[num,txt,raw] = xlsread(filename,sheet) reads the specified worksheet.



所以这里有一个示例程序,它读取 foo.xls进入数字矩阵D和文字信息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;

笔记:
  • 如果您不想要对话框,请替换 inputdlginput
  • 如果有多行具有相同的type值,然后 xy将是向量
  • 我假设 rGMR分别是第 1 列和第 2 列。不知道的可以使用strcmptxt 的第一行. IE。,
    r_col   = strcmp(txt(1,:),'r');
    gmr_col = strcmp(txt(1,:),'GMR');
    
  • 关于excel - 如何从 excel 读取到 matlab 并使用这些信息来查找一些变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6331945/

    相关文章:

    c# - 如何消除尾随的空行/列

    vba - 如果隐藏工作表,我可以将工作表复制到新工作簿吗

    matlab - 在 MATLAB 中使用 textscan() 时忽略“字符

    Excel浮点精度 "ROUND()"hack不起作用

    excel - 将分数键发送到彭博终端

    vba - Excel VBA application.inputbox 工作簿

    filter - 我如何自己编写 Matlab "filter"函数?

    matlab - 在 Matlab 中为绘图着色

    matlab - 查找和删除监听器

    matlab:如果用户按下关闭按钮,则关闭图形用户界面