MATLAB Answers

App Designer Uneditable Code

67 views (last 30 days)
Hello! What I am trying to do is have a 'automated picking list.' In other words, I will have a checklist of item. (I.e. Apple, pear, banana). Each of the items have a specific barcode, 321, 654, and 987 respectively. So, when an item is scanned, I would like it to be automatically 'checked' off the list. Below I put a matlab script with the general idea. I want to implement this logic with the App Designer Toolbox, however I am not able to edit the. Anything with a white background is editable, and a grey background is uneditable. I want to implement the for and if else loops in the .m code to line 49, the value of the checkbox, to change it's toggle instead of print a statement but I cant edit it! any suggestions?
barcode = [321 654 987];
prompt = 'Enter a string of digits to represent a barcode: ';
x = input(prompt);
c = 0;
%For loop will check if scanned item is within list, if so will mark c = 1
for i = 1:length(barcode)
if barcode(i) == x
c = 1;
%If loop will check item if c = 1
if c == 1
disp('Item Checked!')
disp('ERROR: Item Not Required')


Show 3 older comments
Sebastian Caceres
Sebastian Caceres on 15 Jan 2021
Hello! That was very helpful and helped make a lot of progress! I still have one more error after integrating that with the barcode scanner, I've attached it below.
Unrecognized method, property, or field 'Apple' for
class 'litJustACheckBox'.
Error in litJustACheckBox/ScanButtonPushed (line 84)
app.(checkedBoxName).Value = 1; %
read about dynamic field referencing
Error using matlab.ui.control.internal.controller.ComponentController/executeUserCallback (line 386)
Error while evaluating Button PrivateButtonPushedFcn.
I've attached a folder with the link below as well if you could look.
Athrey Ranjith Krishnanunni
You have to use the actual checkbox names for dynamically referencing them as fields of the object app. In your code, you have modified the property checkBoxNames as:
checkBoxNames = {'Apple', 'Pear', 'Banana', 'Orange'}
so the line
app.(checkedBoxName).Value = 1;
evaluates to
app.Apple.Value = 1;
and app.Apple doesn't exist, which is what the error means.
To fix it, use the full names of the checkboxes (you can see them from Component Browser on the right pane), like I had mentioned in my original code:
checkBoxNames = {'AppleCheckBox','PearCheckBox','BananaCheckBox','OrangeCheckBox'};
Sebastian Caceres
Sebastian Caceres on 16 Jan 2021
Worked perfectly, I'll be sure to read more into dynamic references! If you'd like to copy and paste your answer into an answer instead of comment I'd be happy to accept. If not thats also fine, thanks!

Sign in to comment.

Accepted Answer

Athrey Ranjith Krishnanunni
So basically, the trick here is to find which checkbox's value should be changed when the scanned item matches its corresponding barcode.
OP has said that the scanned item is represented by a number x inside a callback function tied to the scanning process.
So we first save the barcodes of all items in the store as a property of the app, along with the actual full names of the checkboxes they each represent.
properties (Access = private)
barcode = [321 654 987];
checkBoxNames = {'AppleCheckBox','PearCheckBox','BananaCheckBox'};
% in the same order as that of barcode
It's important to use the full names of the checkboxes because we'll later use it to refer to the actual checkboxes themselves.
Now, inside the callback function, after x is assigned the barcode of the scanned item, we add the following code:
% see if any entries in barcode are also there in x
isItemChecked = ismember(app.barcode,x);
if ~any(isItemChecked)
disp('ERROR: Item Not Required') % use UIALERT instead to show it on top of your app
% find names of boxes that are checked
checkedBoxes = app.checkBoxNames(isItemChecked);
% change the value of corresponding checkboxes to 1
for itemNo = 1:numel(checkedBoxes)
checkedBoxName = checkedBoxes{itemNo};
app.(checkedBoxName).Value = 1; % read about dynamic field referencing
disp('Item Checked!') % UIALERT like earlier
app.(checkedBoxName) evaluates to app.AppleCheckBox, app.PearCheckBox, etc. depending on context.


Sign in to comment.

More Answers (0)




Community Treasure Hunt

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

Start Hunting!