Convert cell array of latitudes to array
1 回表示 (過去 30 日間)
古いコメントを表示
I have a array of cells containing latitudes in the format {'50.01.234';'etc} how can i convert this into something meaningfull in which i will be able to produce a grid from later?
2 件のコメント
Walter Roberson
2016 年 3 月 7 日
Is 50.01.234 to be a single specification? For example does it mean 50 degrees, 01 minutes, and 234 seconds, which would be the same thing as 50 degrees, 4 minutes and 54 seconds?
回答 (3 件)
KSSV
2016 年 3 月 7 日
k = {'1' ; '3' ; '4' ; '7' ; '10'} ; % be your cell array
N = length(k) ; % gives number of elements in cell array
lon = zeros(N,1) ; % Initialize the lon array
for i = 1:length(k) % Loop for every element
lon(i) = str2num(k{i}) ; % combert sring/ char to number
end
Jan
2016 年 3 月 7 日
Are you sure that you get 50 deg, 1.234 min and not 50 deg 1 min 234 sec (while the last value is a typo only)?
Data = {'50.01.234'; '60.06.345'};
Str = sprintf('%s#'m Data{:});
Value = sscanf(Str, '%i.%f#', [2, numel(Data)]);
Deg = Value(1, :) + Value(2, :) / 60;
0 件のコメント
Walter Roberson
2016 年 3 月 7 日
paired_numeric = str2double( regexp(TheCellArray(:), '\.', 'split', 'once') );
degrees = paired_numeric(:,1) + paired_numeric(:,2) / 60;
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Data Type Conversion についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!