How to convert PgArray to Matlab array?

4 views (last 30 days)
I have written a SQL query to import a table into MATLAB. There is 2 two PgArrays ('org.postgresql.jdbc.PgArray') in the workspace. I need to plot those arrays. How do I convert PgArrays to numeric array so that it is in more manageable format?
datasource = 'live_database';
conn = database(datasource,'postgres','1234');
tablename = "live_table";
query = "SELECT date, coordinatetimes," + ...
" xcoordinates, ycoordinates FROM live_Table WHERE subjectid = 'andrea';";
data = fetch(conn,query);

Accepted Answer

Struggling in MATLAB
Struggling in MATLAB on 23 Apr 2022
Edited: Struggling in MATLAB on 23 Apr 2022
This piece of code will convert PGArray data to double
all_coordinatetimes = cell(length(data_on_date.coordinatetimes),1);
for idx = 1:length(data_on_date.coordinatetimes)
string_all_coordinatetimes = string(data_on_date.coordinatetimes(idx,1));
reg_all_coordinatetimes = regexprep(string_all_coordinatetimes,'{|}','');
split_all_coordinatetimes = split(reg_all_coordinatetimes,',');
all_coordinatetimes{idx,1} = str2double(split_all_coordinatetimes);
data_on_date.coordinatetimes{idx,1} = all_coordinatetimes{idx,1};
end

More Answers (0)

Products


Release

R2022a

Community Treasure Hunt

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

Start Hunting!