How to convert PgArray to Matlab array?

1 visualizzazione (ultimi 30 giorni)
Atanu
Atanu il 13 Mar 2022
Modificato: Atanu il 23 Apr 2022
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);

Risposta accettata

Atanu
Atanu il 23 Apr 2022
Modificato: Atanu il 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

Più risposte (0)

Prodotti


Release

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by