Info

This question is closed. Reopen it to edit or answer.

share some value between callbacks matlab GUI

2 views (last 30 days)
lily bentham
lily bentham on 21 Apr 2015
Closed: MATLAB Answer Bot on 20 Aug 2021
i have four variables which two of them,named 'lat' and 'long' get value in a popup menu like this
case 1
long=48.2331;
lat=30.3653;
...
case 2
long=48.7619;
lat=31.3375;
....
case 3
long=49.84729;
lat=34.13815;
....
case 4
long=48.421726199999966;
lat=38.3236124;
....
otherwise
end
guidata(hObject,handles)
and two others, named 'lat1' and 'long1', which get value in the same way in a different popup menu and this four, finally would be used in a third popup menu like this:
midl=(lat+lat1)/2;
midl1=(long+long1)/2;
midl2=(lat+midl1)/2;
midl3=(long+midl1)/2;
midl4=(lat1+midl)/2;
midl5=(long1+midl1)/2;
first i tried global variables but didn't work at all, then i tried handles structures and read every thing about it and read everything about sharing data and value between functions and callbacks and every question in stack overflow around this topic but it didn't help me. i am new in mat lab so any help and suggestion would be appreciated. thanks in advanced .

Answers (1)

Geoff Hayes
Geoff Hayes on 23 Apr 2015
Lily - see http://www.mathworks.com/matlabcentral/answers/179265-how-to-pass-a-struct-between-callbacks-in-gui for an example of how a struct can be shared between two callbacks. You will want to use the handles structure (assuming that your GUI has been designed with GUIDE) and the guidata function to set and get your latitude and longitude data. Remember that you will have to save the data to the handles structure as
handles.lat = 32;
handles.long = 23;
and then call
guidata(hObject,handles);
to save the updated structure. When you want to access this data from another callback, just get this data as
midl=(handles.lat+handles.lat1)/2;
midl1=(handles.long+handles.long1)/2;

Tags

Community Treasure Hunt

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

Start Hunting!