How to declare variables in a function
35 views (last 30 days)
I am curious as to why the variables 'user' and 'pass' are not recognized by Matlab in the following snippet. When the user launches the function, Matlab throws a undefined function or variable 'pben' where pben is the input from the user.
function update_table(user, pass)
username = user;
password = pass;
datasource = 'SGDOP';
% Connection and SQL query
conn = database(datasource, username, password);
sqlquery = ['SELECT * from table x'];
data = fetch(conn, sqlquery);
Steven Lord on 1 Aug 2019
My guess is that you're trying to call this function like:
That attempts to pass the contents of the variable named pben or the result of calling a function named pben with 0 input arguments and 1 output argument into update_table. If you want to pass the literal text pben into the function, you need to specify it as a char vector or as a string.
If your password is not stored in a variable named somePassword but is the literal text somePassword, you need to pass that in as text as well.