MATLAB Answers

0

How I can convert a single char array in a table with 3 columns?

Asked by Anderson Oliveira on 15 Jun 2019
Latest activity Commented on by 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

Can you give a screenshot of how the table looked on the website?
Assuming that the character vector is stored in a variable named DATA, please show us
DATA(1:50)
DATA(1:50)+0

Sign in to comment.

1 Answer

Answer by Walter Roberson
on 15 Jun 2019
 Accepted Answer

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

  1 Comment

Water,
Thank you so much, I really appreciate your answer.

Sign in to comment.