How to read an xls file in matlab which has latitude (suffixed with N), longitude (suffixed with E), time (prefixed with the month), and a value corresponding to latitude and longitude in it?
조회 수: 5 (최근 30일)
이전 댓글 표시
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/570314/image.jpeg)
The xls file looks like this... The first column is the longitude. I want to extract only the number from it. For example, if the array has a value of "84.375E", I want "84.375" in my corresponding array's value and so on. For the column named "time", I want to similarly extract the number (year). For example, if the cell is "Jun-Sep 1990", I want my corresponding array to have a value of "1990".
I tried to load the values myself. I tried this code:
T = readtable('Myxlsx.xlsx',2);
But I got this error:
Error using readtable (line 245)
All parameters must have an associated value.
Then I tried the xlsread command like this:
T = xlsread('Myxlsx.xlsx');
But then only the values from the fourth column got loaded but nothing from the first three columns appeared.
댓글 수: 2
채택된 답변
Monika Jaskolka
2021년 4월 8일
편집: Monika Jaskolka
2021년 4월 8일
opts = detectImportOptions('Test.xlsx', 'NumHeaderLines', 2, 'VariableNamesRange', 'A1');
T = readtable('Myxlsx.xlsx', opts);
T.Longitude = regexprep(T.Longitude, 'E$', ''); % Remove last E
T.Latitude = regexprep(T.Latitude, 'N$', ''); % Remove last N
T =
4×4 table
Longitude Latitude Time Value
_________ _________ ________________ ________
'84.375' '8.57130' 'June-Sept 1990' 9.58e-06
'86.25' '8.57130' 'June-Sept 1990' 3.14e-05
'88.125' '8.57130' 'June-Sept 1990' 7.11e-05
'90' '8.57130' 'June-Sept 1990' 7.25e-05
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Structures에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!