How to declare variables in a function
이전 댓글 표시
Hi,
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)
% Info
username = user;
password = pass;
datasource = 'SGDOP';
% Connection and SQL query
conn = database(datasource, username, password);
sqlquery = ['SELECT * from table x'];
data = fetch(conn, sqlquery);
save('data.mat', 'data')
end
댓글 수: 4
"pben" is nowhere in this code so the error is coming from somehwere else unless "pben" is an undefined variable you're trying to pass into this function. How are you calling the function? It might be helpful to see the entire copy-pasted error message (all of it).
madhan ravi
2019년 8월 1일
I'm not sure whether you're calling the function right, have a look at https://in.mathworks.com/help/matlab/matlab_prog/run-functions-in-the-editor.html on how to call a function properly.
Blue
2019년 8월 1일
Adam Danz
2019년 8월 1일
My bet is that when you call update_tabel(pben, aaaa), pben is not defined.
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Database Toolbox에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!