problem with pushbutton callbacks for saving user inputted table data.

1 view (last 30 days)
Hi all,
I'm looking for help for this probably simple problem of mine.... Basically, in the middle of a more long and various code I need the user to input or modify some data, so I have an editable table, as you can see below. Of this table i want to extract datas once they have been edited by the user. I haven't been able to make a pushbutton callback function in order to simply save the data to a given variable, so I'm trying another way.
In particular in the following code i try to define the struct "export.table" and set it equal to table.Data. Then in the callback of the pushbutton I ask to copy the new values of table.Data to export.table by the function set... Problem is it's not working. Instead it's giving me the following error:
Error using set
Conversion to double from struct is not possible.
So, what I'm asking is basically if anyone can help me in making this workaround of mine to work, or please help me coding the pushbutton callback function properly. In this second case, please tell me how and where I should write this function, because I've tried many things but none worked...
param = {'Baseline' 'a' 1 'Fixed';...
'Volume' 'b' 2 'Free';...
'X0' 'c1' 3 'Fixed'
'Y0' 'c2' 4 'Free';...
'Angle' 't1' 5 'Fixed';...
'S1' 'w1' 6 'Free';...
'S2' 'w2' 6 'Fixed';};
figure(2)
columnname = {'Parameter','Parameter name','Value','Fixed/Free'};
columnformat = {'char','char','numeric',{'Fixed' 'Free'}};
table = uitable('Data', param,...
'ColumnName', columnname,...
'ColumnFormat', columnformat,...
'ColumnEditable', [false false true true],...
'RowName',[]);
% Set width and height
table.Position(3) = table.Extent(3);
table.Position(4) = table.Extent(4);
table.Position(1) = 100;
table.Position(2) = 100;
export.table = table.Data
p=uicontrol('Style','pushbutton',...
'String','Save the parameters for the fit','Position',[100,75,table.Extent(3),25],'Callback',set(export,'table', get(table,'Data')));
uiwait(gcf);
For completeness I add a trial not working code I wrote for the function, which was saved to a different .m file:
function push_call(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
set(handles.table,'Data', get(handles.table,'Data'))
end
Thx in advance to those willing to help me!
  3 Comments
Andrea Calvi
Andrea Calvi on 20 Dec 2015
My error message is all of what I've written, or at least, that's what is printed on screen in red. If there's somewhere else I should look, please let me know.
the error is given when evaluating the p=uicontrol... line, since if you take that out it would work
Walter Roberson
Walter Roberson on 21 Dec 2015
The red would always include a traceback showing the line the problem occurred on.

Sign in to comment.

Accepted Answer

Walter Roberson
Walter Roberson on 21 Dec 2015
You want to set export.table but which workspace does "export" live in?
Have you considered using waitfor() ? That is, create the pushbutton uicontrol and waitfor() its 'Value' property. Then get() the Data from the table.
This presumes that you are waiting for the user to finish editing the table. If not then I would say just to use questdlg() . questdlg() is very close to what you need even if you are waiting for the user to finish editing, except that to give the user a chance to finish you would want to change WindowStyle to 'normal' instead of 'modal'. You might want to copy the questdlg code and create a non-modal version of it.
  3 Comments
Andrea Calvi
Andrea Calvi on 21 Dec 2015
And sir, you saved my day, here's the updated code, if anyone will ever need it:
table = uitable('Data', param,...
'ColumnName', columnname,...
'ColumnFormat', columnformat,...
'ColumnEditable', [false false true true],...
'RowName',[]);
% Set width and height
table.Position(3) = table.Extent(3);
table.Position(4) = table.Extent(4);
table.Position(1) = 100;
table.Position(2) = 100;
p=uicontrol('Style','pushbutton','String','Save the parameters for the fit','Value',1,'Position',[100,75,table.Extent(3),25]);
waitfor(p,'Value')
param = table.Data;
Apparently pressing a button sets its value to zero...!
Thx again
Walter Roberson
Walter Roberson on 21 Dec 2015
Pushing the button sets the value to the Max property of the uicontrol, which is typically 1. Then releasing the button sets the value to the Min property, which is typically 0.

Sign in to comment.

More Answers (0)

Categories

Find more on App Building 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!