cell array with numeric values only

4 vues (au cours des 30 derniers jours)
Pavan Singh
Pavan Singh le 2 Nov 2020
Commenté : Pavan Singh le 2 Nov 2020
Conver this array to an array with numbers only so it can be used for a graph

Réponse acceptée

VBBV
VBBV le 2 Nov 2020
Modifié(e) : VBBV le 2 Nov 2020
%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
  1 commentaire
Pavan Singh
Pavan Singh le 2 Nov 2020
Thank you, very helpful.

Connectez-vous pour commenter.

Plus de réponses (2)

Stephen23
Stephen23 le 2 Nov 2020
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 le 2 Nov 2020
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

Catégories

En savoir plus sur Get Started with MATLAB dans Help Center et File Exchange

Produits


Version

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by