I have to following problem:
I have a matlab script that consists of a loop. Each loop cycle produces an output. This output has the variable name 'outpt'.
After each cycle in the loop, I would like to take the value of the variable 'outpt' and put this value in a table stored in a datawarehouse.
I am using: Matlab R2012b and Microsoft SQL Server Management Studio 2008
The connection to the SQL table is NOT a problem. I am using these command lines:
%% LOAD SQL DATABASE
% Make connection to server. Note that the password has been omitted.
% Using ODBC driver.
conn = database('servername','','password');
% Read data from database.
e = exec(conn, strcat('INSERT INTO [Tablename].[ref].[REG] ([REGTYP_ID]) VALUES (5555)'));
e = fetch(e);
close(e);
% Assign data to output variable.
SQL_DATA = e.Data;
% Close database connection.
close(conn);
The name of the column in the table is ([REGTYP_ID]. In the SQL string above, I put this value equals 5555. I would like to replace the number '5555' through a variable:
variable=555
%% LOAD SQL DATABASE
% Make connection to server. Note that the password has been omitted.
% Using ODBC driver.
conn = database('servername','','password');
% Read data from database.
e = exec(conn, strcat('INSERT INTO [Tablename].[ref].[REG] ([REGTYP_ID]) VALUES (variable)'));
e = fetch(e);
close(e);
% Assign data to output variable.
SQL_DATA = e.Data;
% Close database connection.
close(conn);
But this does not work. how can I pass a variable in Matlab to a database?
Regards.