Storing only selected data into table using a pushbutton and a checkbutton in GUI

1 visualización (últimos 30 días)
Hello,
I have some values A and B. The problem that I have is when I click on Pushbutton to calculate values AA,BB (which will be stored in a nx1 format columnwise) separately or together, I am not sure how to enable/disable them and display in table Results_table properly depending on which one I select.
My following code for this is:
AA = get(handles.A,'Value');
if AA == 1
%%Perform function. Here I calculate the function AA
AA = num2cell(AA); %%convert it to cell in order to put it in a table
data(:,1) = AA; %%I think here lies the problem, but not sure how to solve it
data1=data(:,1); %%I think here lies the problem, but not sure how to solve it
set(handles.Results_table,'Data', data1);
set(handles.Results_table,'ColumnName',{'AA'}); %%define column name
else
end
same goes here:
BB = get(handles.B,'Value');
if BB== 1
%%Perform function. Here I calculate the function BB%%
BB = num2cell(BB);
data(:,2) = BB; %%I think here lies the problem, but not sure how to solve it
data1=data(:,2); %%I think here lies the problem, but not sure how to solve it
set(handles.Results_table,'Data', data1);
set(handles.Results_table,'ColumnName',{'BB'});
else
end
Now, when I press Pushbutton in order to execute these functions (weather they are previously checked/unchecked with checkbutton) I am not getting a desired result stored in table Results_table with proper column names.
What I want in the end is depending on which checkbutton I select, after pressing the Pushbutton I want to store and display the selected results (weather I select either AA, BB or both of them) in table Results_table with appropriate column names.
What am I doing wrong?
Thanks!
  2 comentarios
Jan
Jan el 5 de Ag. de 2017
I do not understand the problem yet. Which is the handle of the checkbox? What is the contents of handles.A and handles.B? In which function is the posted code found?
Mario
Mario el 5 de Ag. de 2017
Hi Jan,
Sorry, I misinformed some info in the description of the problem.
handles.A and handles.B are my checkbox handles.
And I use functions AA and/or BB to calculate certain parameters by checking/unchecking those checkbox handles.
With checked handles.A or handles.B I want to perform functions and store the results in the table Results_table.
Am I making it any clear now?
Thanks in advance!

Iniciar sesión para comentar.

Respuesta aceptada

Jan
Jan el 5 de Ag. de 2017
Editada: Jan el 5 de Ag. de 2017
With some guessing:
Head = {'A', 'B'};
Data = [num2cell(AA), num2cell(BB)];
Include = ([get(handles.A, 'Value'), get(handles.B, 'Value')] == 1);
set(handles.Results_table, 'Data', Data(:, Include), 'ColumnName', Head(Include));
It is not clear, if handles.A is the checkbox to include/exclude the column, or if it conatins the values. But I hope the idea is clear and you can adjust this to the real problem.

Más respuestas (0)

Categorías

Más información sobre Migrate GUIDE Apps en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by