import data from one gui to another

조회 수: 1 (최근 30일)
pawan kumar
pawan kumar 2011년 10월 10일
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.

답변 (2개)

Daniel Shub
Daniel Shub 2011년 10월 10일
You need to pass the data between the guis with callbacks. There are a number of ways of doing this. Check the FAQ:
  댓글 수: 2
pawan kumar
pawan kumar 2011년 10월 10일
suppose i give input velocity 200 m/s in my main gui and i want to convert it in ft/sec using conversion gui(operated by a push button in main gui using run command ).i want that this input automatically goes to input of unitconversion gui and after selecting desired unit whatever be the output .this output comes in place on input in main gui programe
please wite the callback code also with your answer
thanks
Daniel Shub
Daniel Shub 2011년 10월 10일
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
Iman Alsharkawi 2011년 10월 10일
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!

카테고리

Help CenterFile Exchange에서 Specifying Target for Graphics Output에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by