I am also trying to turn a string of Dates and times into a floating point value corresponding to the time. I have a string array that looks like: "Mon Jun 04 16:18:38 EDT 2018" "Mon Jun 04 16:33:29 EDT 2018" and I need a number array that has a decimal for the time of day. (12:00 am would be 0.000, noon would be 0.500)
How to extract a number from a string array?
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Akzeptierte Antwort
Stephen23
am 21 Jun. 2018
Bearbeitet: Stephen23
am 21 Jun. 2018
"How can extract the first three digit value only so that I get a matrix that is 164 165 165"
With a simple application of regexp and str2double:
>> C = {'(164) - (165)','(165) - (166)','(165) - (166)'};
>> str2double(regexp(C,'\d{3}','match','once'))
ans =
164 165 165
0 Kommentare
Weitere Antworten (1)
Juan Fernandez
am 21 Jun. 2018
I searched through older questions and found a similar one from 2012. The solution requires the use of regexp(_). Here's my implementation.
str1 = '(164) - (165)';
str2 = '(165) - (166)';
str3 = '(165) - (166)';
strs = {str1,str2,str3};
output = zeros(length(strs),1);
for iter=1:length(strs)
num_strs = regexp(strs{iter},'\d*','Match');
output(iter) = str2double(num_strs{1});
end
0 Kommentare
Siehe auch
Kategorien
Mehr zu Characters and Strings finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!