App Designer Uneditable Code
Show older comments
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;
end
end
%If loop will check item if c = 1
if c == 1
disp('Item Checked!')
else
disp('ERROR: Item Not Required')
end
6 Comments
Athrey Ranjith Krishnanunni
on 13 Jan 2021
In your app, where does the value of x (shown in your script) come from?
Sebastian Caceres
on 13 Jan 2021
Edited: Sebastian Caceres
on 14 Jan 2021
Athrey Ranjith Krishnanunni
on 14 Jan 2021
First you need to save barcode as a property of app, along with the names of the corresponding check boxes:
properties (Access = private)
barcode = [321 654 987];
checkBoxNames = {'AppleCheckBox','PearCheckBox','BananaCheckBox'};
% in the same order as that of barcode
end
Now, in the method where x is read from simulink, put the following code after x is assigned the required value:
% see if any entries in barcode are also there in x
isItemChecked = ismember(app.barcode,x);
if ~any(isItemChecked)
disp('ERROR: Item Not Required') % you might want to use UIALERT instead
return
end
% 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
end
disp('Item Checked!') % UIALERT like earlier
Sebastian Caceres
on 15 Jan 2021
Athrey Ranjith Krishnanunni
on 16 Jan 2021
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
on 16 Jan 2021
Accepted Answer
More Answers (0)
Categories
Find more on Multidimensional Arrays 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!