How to build the search fast?
이전 댓글 표시
Hi I have a database with cost assigned to over 500 zipcodes, that is, one zipcode has a corresponding cost. I want to build a function in matlab, that each time I have a zipcode it will return the cost. Is there a way to do it efficiently?
I have a plan to build a matrix, each row has a zipcode and a cost. I can input it but when I find it I need to go over all zipcodes to find the cost. Zipcodes are not consecutive by the way.
Thanks.
채택된 답변
추가 답변 (1개)
Image Analyst
2012년 12월 24일
Why not just have a simple 500 by 2 numerical matrix to store the zip codes and the costs? Say you call it "zipCodeLookUpTable". Each row lists the zip code (in the first column) and the cost (in the second column). Then if you want to find the cost of a zip code, say it's called thisZipCode, find the row by looking in the first column, and then get the cost from the second column:
% Get the row where this zip code is located.
row = find(zipCodeLookUpTable(:,1) == thisZipCode);
% Get cost for this zip code.
cost = zipCodeLookUpTable(row, 2);
댓글 수: 5
C Zeng
2012년 12월 25일
Image Analyst
2012년 12월 25일
Yes. Did you look up Excel in the help? You would have found the function xlsread() mentioned.
C Zeng
2012년 12월 25일
Image Analyst
2012년 12월 26일
save() will save MATLAB data out to a disk file in a proprietary MATLAB format .mat file. It will not import data in an Excel file into MATLAB.
C Zeng
2012년 12월 28일
카테고리
도움말 센터 및 File Exchange에서 Data Import from MATLAB에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!