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

4 次查看(过去 30 天)
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

采纳的回答

Kevin Holly
Kevin Holly 2024-3-13
编辑:Kevin Holly 2024-3-13
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 个评论
Connor
Connor 2024-3-14
After using the break point at the end of the function, I can confirm that it is a string array.
Connor
Connor 2024-3-14
编辑:Connor 2024-3-14
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.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Interactive Control and Callbacks 的更多信息

产品


版本

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by