Convert cell array of latitudes to array

조회 수: 1 (최근 30일)
aaron Harvey
aaron Harvey 2016년 3월 7일
답변: Walter Roberson 2016년 3월 7일
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
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?
aaron Harvey
aaron Harvey 2016년 3월 7일
sorry i should have specified this. Its actually deg and decimal , so 50.01.234 would be 50degrees and 01.234 minutes. i would like to be able to take them from the array of cells eventually to be able to plot the points on a grid map

댓글을 달려면 로그인하십시오.

답변 (3개)

KSSV
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
  댓글 수: 1
aaron Harvey
aaron Harvey 2016년 3월 7일
I'm affraid this hasn't worked, it handles numbers such as your example fine but it does not handle the second decimal point well such as 50.01.234

댓글을 달려면 로그인하십시오.


Jan
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;

Walter Roberson
Walter Roberson 2016년 3월 7일
paired_numeric = str2double( regexp(TheCellArray(:), '\.', 'split', 'once') );
degrees = paired_numeric(:,1) + paired_numeric(:,2) / 60;

카테고리

Help CenterFile Exchange에서 Data Type Conversion에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by