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

조회 수: 2 (최근 30일)
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
Jan
Jan 2017년 8월 5일
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 2017년 8월 5일
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!

댓글을 달려면 로그인하십시오.

채택된 답변

Jan
Jan 2017년 8월 5일
편집: Jan 2017년 8월 5일
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.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Standard File Formats에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by