xlsread to retrieve information based on input
古いコメントを表示
Hello!
I am working on a chemical engineering calculator of sorts and need to retrieve data from a sizable excel sheet. I have a number of function files that needs different information from the sheet.
The first column is all component names, and the following columns have info like critical pressure and temp, heat capacity constants, etc.
Is there a way for xlsread to search the component column for a particular string (ie "water" or "ethanol") and so i can get the properties for just the component of interest (user specified)?
Or is using xlsread just the wrong way to go about what I'm trying to do?
Many thanks!
回答 (2 件)
Fangjun Jiang
2011 年 12 月 11 日
If the data sheet is not extremely large, you can use xlsread() to read in all the data and then process it.
[Num,Txt,Raw]=xlsread(YouExcelFile);
Assume Raw is below:
Raw={'water',1,2,3;'ethanol',10,20,30};
Index=strcmp(Raw(:,1),'water');
FindValue=Raw(Index,:);
FindValue =
'water' [1] [2] [3]
5 件のコメント
Michael
2011 年 12 月 11 日
Image Analyst
2011 年 12 月 11 日
"Sizable"? That's microscopic. Just read the whole thing in and don't worry about it - your computer will barely even notice something that tiny read into memory.
Fangjun Jiang
2011 年 12 月 11 日
It should work. Use ComName=input('prompt','s') to get a sting input. use strcmpi() if it is not case sensitive. You don't need a loop to search. Just use Index=strcmp() above. Take a look at the value of Index and you'll understand how it works.
Michael
2011 年 12 月 11 日
Fangjun Jiang
2011 年 12 月 11 日
If you want the linear index, instead of the logical index, you can use
n=find(strcmpi(Data(:,1),component)),
Michael
2011 年 12 月 11 日
2 件のコメント
Walter Roberson
2011 年 12 月 11 日
Earlier you were referring to an array named "data" and now you refer to "Data" ??
Michael
2011 年 12 月 11 日
カテゴリ
ヘルプ センター および File Exchange で Spreadsheets についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!