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

guiguideimage analysisimage processingmatlab gui

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!

Best Answer

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.