xlsread to retrieve information based on input
Afficher commentaires plus anciens
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!
Réponses (2)
Fangjun Jiang
le 11 Déc 2011
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 commentaires
Michael
le 11 Déc 2011
Image Analyst
le 11 Déc 2011
"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
le 11 Déc 2011
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
le 11 Déc 2011
Fangjun Jiang
le 11 Déc 2011
If you want the linear index, instead of the logical index, you can use
n=find(strcmpi(Data(:,1),component)),
Michael
le 11 Déc 2011
2 commentaires
Walter Roberson
le 11 Déc 2011
Earlier you were referring to an array named "data" and now you refer to "Data" ??
Michael
le 11 Déc 2011
Catégories
En savoir plus sur Text Data Preparation dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!