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에서 Text Data Preparation에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!