xlsread to retrieve information based on input
Ältere Kommentare anzeigen
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!
Antworten (2)
Fangjun Jiang
am 11 Dez. 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 Kommentare
Michael
am 11 Dez. 2011
Image Analyst
am 11 Dez. 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
am 11 Dez. 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
am 11 Dez. 2011
Fangjun Jiang
am 11 Dez. 2011
If you want the linear index, instead of the logical index, you can use
n=find(strcmpi(Data(:,1),component)),
Michael
am 11 Dez. 2011
2 Kommentare
Walter Roberson
am 11 Dez. 2011
Earlier you were referring to an array named "data" and now you refer to "Data" ??
Michael
am 11 Dez. 2011
Kategorien
Mehr zu Spreadsheets finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!