我有一个包含导体信息的 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;
笔记:
inputdlg
与 input
type
值,然后 x
和 y
将是向量 r
和 GMR
分别是第 1 列和第 2 列。不知道的可以使用strcmp
在 txt
的第一行. IE。,r_col = strcmp(txt(1,:),'r');
gmr_col = strcmp(txt(1,:),'GMR');
关于excel - 如何从 excel 读取到 matlab 并使用这些信息来查找一些变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6331945/