Pass data from figure to main GUIDE pushbutton callback function

I created a pushbutton in main gui using guide and also programmatically created a figure with pushbutton which inputs data. How can I pass the data when the pushbutton is press from the figure and send it to the main gui pushbutton callback function? I have attached an image for clarification.

 採用された回答

KL
KL 2017 年 11 月 20 日
編集済み: KL 2017 年 11 月 20 日

1 投票

You need to update the hObject handle using,
guidata(hObject,handles);
Upon edit, save the new table data in this handle,
hObject.TableData = get(uitableHandle,'Data');
and then in the pushbutton callback use it like,
plot(hObject.TableData)

3 件のコメント

Kim Lopez
Kim Lopez 2017 年 11 月 20 日
I had this code for figure and store the data on tableData3 variable.
function pushbutton_Callback(hObject, eventdata, handles)
hfig = figure('Position',[700 200 240 200],'Name','Add Derated Unit','NumberTitle','off');
derated = uitable(hfig);
derated.ColumnName = {'Rating(MW)','FOR/State Probability'};
derated.RowName = [];
derated.Data = [0 0; 0 0; 0 0];
derated.Position(3) = derated.Extent(3);
derated.Position(4) = derated.Extent(4);
derated.ColumnEditable = [true true];
btn = uicontrol('Style', 'pushbutton', 'String', 'Add Row',...
'Position', [20 170 50 20], 'Callback', {@add_row, derated});
add = uicontrol('Parent', hfig, 'Style', 'pushbutton', 'String', 'Add Unit',...
'Position', [100 170 50 20], 'Callback', {@add_derated, derated});
function add_row(btn, ~, derated)
data = get(derated, 'data');
data(end+1,:) = 0;
set(derated,'data',data);
derated.Position(3) = derated.Extent(3);
derated.Position(4) = derated.Extent(4);
function add_derated(add, ~, derated)
tableData3 = get(derated, 'data');
disp(tableData3)
I having hard time to figure out how can I share the data to
function main_pushbutton_Callback(hObject, eventdata,handles)
KL
KL 2017 年 11 月 20 日
After you update the derated table (be it anywhere), do
hObject.deratedData = derated.Data;
guidata(hObject,handles);
Now your changes are updated to the structure. Now when you are inside your main paushbutton callback, retrieve it like,
dataToPlot = hObject.deratedData;
Kim Lopez
Kim Lopez 2017 年 11 月 20 日
Wow, that works well. Thank you so much.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeInteractive Control and Callbacks についてさらに検索

質問済み:

2017 年 11 月 20 日

コメント済み:

2017 年 11 月 20 日

Community Treasure Hunt

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

Start Hunting!

Translated by