Call Edit text from another Edit text in another Gui

in PhatHienLSB.M i have a PushMo_Callback
function PushMo_Callback(hObject, eventdata, handles)
% hObject handle to PushMo (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
[filename, pathname] = uigetfile( ...
{
'*.bmp','BMP (*.bmp)'; ...
'*.png','PNG(*.png)'; ...
'*.jpg', 'JPG (*.jpg)'; ...
'*.*', 'All Files (*.*)'}, ...
'Moi ban chon tep anh');
set(handles.Edit1,'String',[filename,pathname]);
TachTin.m
function TachThongDiep_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to TachThongDiep (see VARARGIN)
% Choose default command line output for TachThongDiep
handles.output = hObject;
filename=get(handles.PhatHienLSB.Edit1,'String');
set(handles.Edit2,'string',filename');
% Update handles structure
guidata(hObject, handles);
help me
--> filename=get(handles.PhatHienLSB.Edit1,'String');
-->set(handles.Edit2,'string',filename');

 Réponse acceptée

Andrew
Andrew le 24 Oct 2012
TachTongDiep doesn't know what the handle is for PhatHienLSB. So when you call handles.PhatHienLSB.Edit1 in TachTongDiep, it doesn't know you want to use the handles structure for PhatHienLSB. You need to pass the handles structure for PhatHienLSB to TachTongDiep. See getappdata and setappdata in the Matlab documentation, or use global variables, either way:
function PushMo_Callback(hObject, eventdata, handles)
[filename, pathname] = uigetfile( ...
{'*.bmp','BMP (*.bmp)'; ...
'*.png','PNG(*.png)'; ...
'*.jpg', 'JPG (*.jpg)'; ...
'*.*', 'All Files (*.*)'}, ...
'Moi ban chon tep anh');
set(handles.Edit1,'String',[filename,pathname]);
setappdata(0,'handles_PhatHienLSB',handles)
function TachThongDiep_OpeningFcn(hObject, eventdata, handles, varargin)
handles.output = hObject;
guidata(hObject, handles);
handles_PhatHienLSB = getappdata(0,'handles_PhatHienLSB');
filename = get(handles_PhatHienLSB.Edit1,'String');
set(handles.Edit2,'String',filename);
At least I think that's the answer, I'm still kind of a novice though, some of the other guys here should be able to help out more.

3 commentaires

nguyen
nguyen le 24 Oct 2012
Modifié(e) : nguyen le 24 Oct 2012
Thank you very much but i program still error
this is error " Attempt to reference field of non-structure array.
filename = get(handles_PhatHienLSB.Edit1,'String');
Note: I wanna to get data from Edit1 to Edit2
Are Edit1 and Edit2 in the same GUI? I assumed Edit1 was in PhatHienLSB and Edit2 was in TachThongDiep.
If you are getting that error then the problem is with
setappdata(0,'handles_PhatHienLSB',handles)
Make sure that you have that line at the end of PushMo. I tried it and it worked.
nguyen
nguyen le 24 Oct 2012
ok. it worked. Thank you very much

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Graphics Objects dans Centre d'aide et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by