Conver this array to an array with numbers only so it can be used for a graph

 채택된 답변

VBBV
VBBV 2020년 11월 2일
편집: VBBV 2020년 11월 2일

1 개 추천

%if true
% code
% end
C = {'long: 151.125#';'long: 151.126#'}
for i=1:length(C)
nn{i}=(C{i}(7:13));
end
A = cell2mat(nn')
B = str2num(A)% array with numbers only

추가 답변 (2개)

Stephen23
Stephen23 2020년 11월 2일

0 개 추천

Do NOT use loops or cellfun for this, unless you really want to write complex and slow MATLAB code.
The most efficient solution is to use sscanf like this:
C = {'long: 151.125#';'long: 151.126#'};
V = sscanf([C{:}],'long:%f#')
V = 2×1
151.1250 151.1260
Akira Agata
Akira Agata 2020년 11월 2일

0 개 추천

Another possible solution:
C = {'long: 151.125#';'long: 151.126#'};
V = regexp(C,'[?\d.]+','match','once');
V = str2double(V);
>> V
V =
151.1250
151.1260

카테고리

도움말 센터File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

제품

릴리스

R2020a

질문:

2020년 11월 2일

댓글:

2020년 11월 2일

Community Treasure Hunt

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

Start Hunting!

Translated by