Storing only selected data into table using a pushbutton and a checkbutton in GUI
2 views (last 30 days)
Show older comments
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 Comments
Jan
on 5 Aug 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?
Accepted Answer
Jan
on 5 Aug 2017
Edited: Jan
on 5 Aug 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.
More Answers (0)
See Also
Categories
Find more on Data Import and Analysis in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!