How to run MATLAB function on each row of database?

1 次查看(过去 30 天)
I have wrote a MATALAB function to get an output. I import the PostgreSQL database to MATLAB workspace and then work from there. For the function, I fetch the inputs from the database. Now I need to run the function on each row of the database and put the results back in the database in a new column. How should I proceed with this? Any suggestion is appreciated.
  18 个评论
dpb
dpb 2022-5-23
"...I can not run all at a time. I need to run 10-20 rows at a time."
Why's that? 25K rows is all that much data unless there are thousands of values per row. Unless retrieving the data from the database hangs up or somesuch? I've never used the database connection so have no idea how efficient it is, but if you can retrieve the data, I see no reason it shouldn't be able to be handled in toto in memory.
We're still pretty limited in what you've said about what the function(s) need to do -- I see Walter had time to poke at the data a little, I've not had that opportunity yet and may not until later in the day today with other commitments, but "so if there is 5 'subjectid' on '03-Apr-2022', 5 x 40 trails need to be pooled together." what does "pooled" mean, specifically?
Atanu
Atanu 2022-5-30
The problem has been solved. I used a for loop for this. I imported the database as a table 'all_data'.
loadfile = load('all_data.mat');
all_data = loadfile.all_data;
rows = 4;
logical_out = cell(rows,1); run_time = cell(rows,1);
reaction_time = cell(rows,1); average_position = cell(rows,1);
position_when_offered = cell(rows,1);
for row = 1:rows
[logical_out{row}, run_time{row}, reaction_time{row}, average_position{row}, ...
position_when_offered{row}] ...
= new_table2(string(all_data.subjectid(row)),string(all_data.date(row)),string(all_data.trialname(row)));
end

请先登录,再进行评论。

采纳的回答

Atanu
Atanu 2022-5-30
The problem has been solved. I used a for loop for this. I imported the database as a table 'all_data'.
loadfile = load('all_data.mat');
all_data = loadfile.all_data;
rows = 4;
logical_out = cell(rows,1); run_time = cell(rows,1);
reaction_time = cell(rows,1); average_position = cell(rows,1);
position_when_offered = cell(rows,1);
for row = 1:rows
[logical_out{row}, run_time{row}, reaction_time{row}, average_position{row}, ...
position_when_offered{row}] ...
= new_table2(string(all_data.subjectid(row)),string(all_data.date(row)),string(all_data.trialname(row)));
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