Borrar filtros
Borrar filtros

How to run MATLAB function on each row of database?

8 visualizaciones (últimos 30 días)
Atanu
Atanu el 21 de Mayo de 2022
Respondida: Atanu el 30 de Mayo de 2022
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 comentarios
dpb
dpb el 23 de Mayo de 2022
"...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 el 30 de Mayo de 2022
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

Iniciar sesión para comentar.

Respuesta aceptada

Atanu
Atanu el 30 de Mayo de 2022
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

Más respuestas (0)

Categorías

Más información sobre Data Type Conversion en Help Center y File Exchange.

Productos


Versión

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by