フィルターのクリア

Info

この質問は閉じられています。 編集または回答するには再度開いてください。

share some value between callbacks matlab GUI

1 回表示 (過去 30 日間)
lily bentham
lily bentham 2015 年 4 月 21 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
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 .

回答 (1 件)

Geoff Hayes
Geoff Hayes 2015 年 4 月 23 日
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;

この質問は閉じられています。

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by