import data from one gui to another
1 view (last 30 days)
Show older comments
i have made a gui of unit conversion. i want to use this in another gui for changing units of variable. i want to import data from unit conversion gui to my original gui. is it possible to do so. if yes then how can i implement in.
0 Comments
Answers (2)
Daniel Shub
on 10 Oct 2011
You need to pass the data between the guis with callbacks. There are a number of ways of doing this. Check the FAQ:
2 Comments
Daniel Shub
on 10 Oct 2011
You haven't really provided enough information to write the callback. Even if you did provide more information, I am not going to write a callback function for you. If you have a question about the concept of callbacks, ask that. If you have a specific question about how to implement a callback ask that. In general, don't ask for code.
Iman Alsharkawi
on 10 Oct 2011
In the main gui, make a function callback similar to the one below:
function [] = getscale(varargin)
scale = conversion_gui %where conversion_gui is the name of your function for your other gui
Then in the new gui, conversion_gui, set up how you want your gui to work, buttons and whatnot, then add callbacks similar to the following:
function [conv_value] = conversion_gui(varargin)
%enter all your uicontrols here...
handles.conversion_gui_window = ...
figure(...)
%...
%...
uiwait(handles.conversion_gui_window)
if isappdata(0,'ListConvAppData')
getval = getappdata(0,'ListConvAppData');
conv_value = getval;
rmappdata(0,'ListConvAppData')
else
% figure was deleted
conv_value = 0;
end
%--------------------------------------------------------------------------
%%OK callback
function OKcb(varargin)
if (~isappdata(0, 'ListConvAppData'))
conv_value = get(gcf,'userdata');
setappdata(0,'ListConvAppData',conv_value);
delete(gcbf);
end
%%Cancel callback
function cancelcb(varargin)
hwinedit = varargin{3};
conv_value= 0;
setappdata(0,'ListConvAppData',conv_value)
delete(gcbf);
Keep in mind that this particular code closes the conversion_gui window when the user hits the ok or cancel button (if you have one). You can modify the code however you want and use the setappdata, getappdata, rmappdata functions in Matlab to pass values from one gui to another. Also, I'm just saving the value in the 'userdata' for your figure window. You can save it anywhere and just call that location for your values.
Hope this helps!
0 Comments
See Also
Categories
Find more on Interactive Control and Callbacks 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!