Brace Indexing Not Supported when in matlab app designer but when transferred to matlab script, it works properly.
1 view (last 30 days)
Show older comments
Hello, I am trying to make an application that connects Matlab to arduino and a simple database. In a nutshell I want to scan an RFID to get its UID. This UID is registered in the database and has corresponding student names. when using the script shown below in Matlab command window, it works properly. It extracts the student name from the database using the UID scanned from the arduino.
%This first script is run in the command line
%I connect Matlab to my database and arduino
conn = database('Library','','');
arduinoPort = serialport("COM3", 115200, "Timeout",16);
%i send a command to arduino using serial communication and read the output of the arduino
write(arduinoPort, 's', "char");
id = readline(arduinoPort);
%I set up an SQL query and execute it in my database
query = sprintf('SELECT StudentName FROM StudentInfo WHERE StudentID = %s', id);
cursor = exec(conn, query);
%I get the result and place the data (student name) in studentName
results = fetch(cursor);
studentName = results.Data{1};
However, when I tried to transfer the script to Matlab app designer, it reveals an error saying "Brace indexing is not supported for variables of this type". the only changes I made were making it a function, and adding the necessary variables.
function getStudentInfo(app, StudentID)
query = sprintf('SELECT StudentName FROM StudentInfo WHERE StudentID = ''%s''', StudentID);
cursor = exec(app.conn, query);
results = fetch(cursor);
app.StudentName = results.Data{1};
end
Of course, I connected it properly to the database and arduino before calling the function. I also verified that I indeed scanned the correct UID.
I tried removing the {1} since i'm only extracting one name. It eliminates the brace indexing errorbut to see what is happening, I also tried to use msgbox() just to see what is stored in app.StudentName. It resulted in an error saying that the expected input was a char or string. The error says the data was double which is of itself the wrong data type. I tried converting it and the result was displaying only "0".
I am now lost and don't know what to do. Your help is very much appreciated. Thank you!
2 Comments
See Also
Categories
Find more on Arduino Hardware in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!