How to convert PgArray to Matlab array?

조회 수: 4 (최근 30일)
Struggling in MATLAB
Struggling in MATLAB 2022년 3월 13일
편집: Struggling in MATLAB 2022년 4월 23일
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);

채택된 답변

Struggling in MATLAB
Struggling in MATLAB 2022년 4월 23일
편집: Struggling in MATLAB 2022년 4월 23일
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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Database Toolbox에 대해 자세히 알아보기

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by