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

11 visualizaciones (últimos 30 días)
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

Respuesta aceptada

Kevin Holly
Kevin Holly el 13 de Mzo. de 2024
Editada: Kevin Holly el 13 de Mzo. de 2024
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 comentarios
Connor
Connor el 14 de Mzo. de 2024
After using the break point at the end of the function, I can confirm that it is a string array.
Connor
Connor el 14 de Mzo. de 2024
Editada: Connor el 14 de Mzo. de 2024
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.

Iniciar sesión para comentar.

Más respuestas (0)

Productos


Versión

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by