file handling with coordinates
1 回表示 (過去 30 日間)
古いコメントを表示
I have to write a code that organizes a text file filled with coordinates and organize them by latitude or longitude for each state(EX: CA would be North-South and Tennessee would be East-West) and then print out the cities in order by distance for whichever state the user inputted. I have attached the text file. I am not expecting somebody else to do the work for me. I just don't know where to start. Specifically I don't know how I would go about beginning to organize the cities per state.
Any and all help would be greatly appreiciated. Thank you!
2 件のコメント
回答 (1 件)
jonas
2018 年 10 月 12 日
編集済み: jonas
2018 年 10 月 12 日
I would approach this roughly as follows:
- Read all coordinates and group them by state
- Use a grouping function ( findrows/ splitapply, varfun, grpstats) to calculate the max/min long/lat in each state (4 values per state
- If you have the mapping toolbox, calculate the east-west and north-south arclength to find the longest distance.
- Use a grouping function again to output a sorted list of cities per state that is returned to the user upon request.
Try yourself, and ask if you have trouble with one of the steps.
3 件のコメント
Walter Roberson
2018 年 10 月 15 日
Have you considered creating a vector of target lat or long values, and a cell array of character vectors with the names of the states? And use ismember() to match the input state to the name list, getting out an index (second output of ismember) that you use to index the lat or long array?
I do not know what those lat or long values are doing for you? And I am concerned because you have not defined both of them for each state, which always leads to the risk that you could accidentally use a value appropriate for the previous state.
jonas
2018 年 10 月 15 日
That does not look optimal. Where did you get those coordinates from? Is it the "length" of the state in units of degrees? Do you know that you cannot compare latitude and longitude in absolute terms? You should compare arclength if you want to calculate the "length" of the state.
参考
カテゴリ
Help Center および File Exchange で Customize Object Display for Classes についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!