Checkboxes values don't change after checking them off in UItable in app designer

I am struggling to understand why my logical variables are not changing in value after selecting them in the UItable.
I have included a picture of my checkboxes and variables in my base workspace in matlab that would correlate to the first column shown in the image.
The following function is how the values change in my code. To update it after channels have been selected I using the following;
function UpdateUITable(app, subsystem)
% Initialize visibility and calibration logical arrays
app.IndvCal = false(size(subsystem.ChannelNames));
app.ofchan = false(size(subsystem.ChannelNames));
% list all the channel names
app.Channels = string(subsystem.ChannelNames);
% Create a cell array with channel names, on/off switch for the channel and the calibration,
UIData = [app.Channels, app.ofchan, app.IndvCal];
% Update the UITable data
app.UITable.Data = UIData;
end
and to update which channels are suppose to be being shown and/or calibrated is;
function UITableCellEdit(app, event)
for i = 1:8
if app.ofchan(i,1) == true
app.SelectedChannels(i,1) = i;
end
% if the third column is being checked for everyrow if the value
% is true list which row/column it is in
if app.IndvCal(i,1) == true
app.SelectedCal(i,1) = i;
end
end
assignin("base","ofchan",app.ofchan)
assignin("base","IndvCal",app.IndvCal)
assignin("base","SelectedChannels",app.SelectedChannels)
assignin("base","SelectedCal",app.SelectedCal)
% Call the function that uses the selected channels (e.g., data calibration)
updateChannelMeasurementComponents(app)
end
All the values of the assignin variables are 0 but I am unsure why. I checked the logic on the for loop in a livescript and it should work. I think I might need to change the length of the following properties (app.SelectedChannels && app.SelectedCal), but, I do not know how to go about it and only keep the values that would be stored into them using the for loop.
I know that I am missing something here but I am having a hard time trying to figure out what the issue is. Any and all help is appreciated.
Thanks

 Accepted Answer

Below the logical array, app.ofchan, is defined as all false (0) .
app.ofchan = false(size(subsystem.ChannelNames));
If you want to change the value of app.ofchan after you interact with app.UITable. You can add the following line.
app.ofchan = app.UITable.Data(:,2)
When you interact with app.UITable, you change app.UITable.Data and not app.ofchan. The above line would update the value of app.ofchan.
You may want to consider using app.UITable in place of app.IndvCal, app.ofchan, and app.Channels, unless these variable will be used elsewhere and are distinctly different from the columns in the app.UITable.

12 Comments

I am now getting the error on the first line of code in the second code block listed.
Error using LiveDataAcquisition_MultiChannel_Saving/UITableCellEdit
Error setting property 'ofchan' of class 'LiveDataAcquisition_MultiChannel_Saving'. Value must be of type logical
or be convertible to logical.
I dont use them anywhere else I only use the app.SelectedCal & the app.SelectedChannels
I also have changed the function to;
app.ofchan = app.UITable.Data(:,2);
app.IndvCal = app.UITable.Data(:,3);
% Update SelectedChannels based on ofchan
app.SelectedChannels = find(app.ofchan);
% Update SelectedCal based on IndvCal
app.SelectedCal = find(app.IndvCal);
%
disp(app.IndvCal)
disp(app.ofchan)
% Call the function that uses the selected channels (e.g., data calibration)
updateChannelMeasurementComponents(app)
Do you know why I might be getting this error? I have defined the variable as a logical and it is reading out as a logical and has false(0) values already in it.
I also also defined them as private properties for the purpose of the initialization of the UITable and the celledit callback needing to be in seperate functions. Does that make sense?
Thanks
Could I use the app.UITable.Data for the find() function?
Hmm, make sure that your table columns are the right format.
app.UITable.ColumnFormat= {'char','logical','logical'};
Yes, you can use app.UITable.Data to find the selected channels using the find() function
% Update SelectedChannels based on ofchan
app.SelectedChannels = find(app.UITable.Data(:,2));
% Update SelectedCal based on IndvCal
app.SelectedCal = find(app.UITable.Data(:,3));
I am now getting the error, I do have my columns formatted correctly
Undefined function 'find' for input arguments of type 'string'.
Error using find
Incorrect number or types of inputs or outputs for function find.
Error in LiveDataAcquisition_MultiChannel_Saving/UITableCellEdit (line 854)
app.SelectedCal = find(app.UITable.Data(:,3));
Is it trying to read all of the UITable Data?
It appears the datatype for app.UITable.Data(:,3), which is the 3rd column of the uitable, is a string. Make sure you define column 3 as a logical datatype.
You can do this with:
app.UITable.ColumnFormat= {'char','logical','logical'};
I have these lines of code as a part of my startupFcn
app.UITable.ColumnFormat = {'char', 'logical','logical'};
app.UITable.ColumnEditable = [false, true, true];
I while looking through other posts I noticed that they had to use the get(handles()) to revtrieve data from the cells once they have been edited. could this be the problem?
I added
UITData = get(handles.UITable, 'Data');
line to my code but, am no getting an error
"Unable to resolve the name 'handles.UITable'."
on the line above.
I'm curious if
app.IndvCal = false(size(subsystem.ChannelNames));
app.ofchan = false(size(subsystem.ChannelNames));
% list all the channel names
app.Channels = string(subsystem.ChannelNames);
% Create a cell array with channel names, on/off switch for the channel and the calibration,
UIData = [app.Channels, app.ofchan, app.IndvCal];
% Update the UITable data
app.UITable.Data = UIData;
converts all the columns into strings. I suspect UIData is a string datatype.
Try placing
app.UITable.ColumnFormat = {'char', 'logical','logical'};
after this.
Can you go in debug mode and check the datatype of app.UITable.Data(:,3)?
I just replaced them, I am not completly sure how to use breakpoints/go into debug mode. I will try using assign in after these to see if the value is now logical and see if it wasn't before.
You can click the line numbers within the script to create a breakpoint. Once the code hits this breakpoint, it will enter debug mode and open up the workspace the current line is using.
Okay, good to know. I did use assignin and they are strings. Is this becuase the checkboxes take the value 1 once they are checked off? they are continuing to be strings even after I changed the function to
function UpdateUITable(app, subsystem)
% Initialize visibility and calibration logical arrays
app.IndvCal = false(size(subsystem.ChannelNames));
app.ofchan = false(size(subsystem.ChannelNames));
% list all the channel names
app.Channels = string(subsystem.ChannelNames);
% Create a cell array with channel names, calibration, and visibility values
UIData = [app.Channels, app.ofchan, app.IndvCal];
% Update the UITable data
app.UITable.Data = UIData;
% Set up column format and column editable properties
app.UITable.ColumnFormat = {'char', 'logical','logical'};
app.UITable.ColumnEditable = [false, true, true];
end
Is there something else I should do? Thanks for all the help!
After using the break point at the end of the function, I can confirm that it is a string array.
I ended up fixing it by chaning the data into a table and then using table2array when outputting the values. Now am having problems relating to plotting the channels that I have selected and calibrating them.

Sign in to comment.

More Answers (0)

Categories

Find more on Develop Apps Using App Designer in Help Center and File Exchange

Products

Release

R2023b

Asked:

on 12 Mar 2024

Edited:

on 14 Mar 2024

Community Treasure Hunt

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

Start Hunting!