How I can convert a single char array in a table with 3 columns?
5 views (last 30 days)
Show older comments
Anderson Oliveira
on 15 Jun 2019
Commented: Anderson Oliveira
on 15 Jun 2019
I import a data from a web site with API, the data is a single char, 1-by-1, and I need to convert in a table with 3 columns, {year, month, data}
'Latitude (decimal degrees): 45.000Longitude (decimal degrees): 5.000Radiation database: PVGIS-CMSAFOptimal slope angle (deg.): Year Month Hh2005 Jan 45.52005 Feb 50.32005 Mar 1132005 Apr 1402005 May 1892005 Jun...
3 Comments
Walter Roberson
on 15 Jun 2019
Assuming that the character vector is stored in a variable named DATA, please show us
DATA(1:50)
DATA(1:50)+0
Accepted Answer
Walter Roberson
on 15 Jun 2019
Suppose you have the character vector stored in the variable S. Then:
info_struct = regexp(S, '(?<Year>\d{4})\s+(?<Month>[A-Za-z]{3})\s+(?<Hh>\d+(\.\d+)?)','names');
Year = str2double({info_struct.Year}.');
Month = vertcat(info_struct.Month);
Hh = str2double({info_struct.Hh}.');
YourTable = table(Year, Month, Hh);
More Answers (0)
See Also
Categories
Find more on String Parsing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!