Checkboxes values don't change after checking them off in UItable in app designer
조회 수: 7 (최근 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
댓글 수: 0
채택된 답변
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
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Whos에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!