Update GUIDE GUI when radiobutton is selected
現在この質問をフォロー中です
- フォローしているコンテンツ フィードに更新が表示されます。
- コミュニケーション基本設定に応じて電子メールを受け取ることができます。
エラーが発生しました
ページに変更が加えられたため、アクションを完了できません。ページを再度読み込み、更新された状態を確認してください。
古いコメントを表示
I made a radiobutton group in my GUI made in GUIDE, but cannot find a callbackFcn for the radiobuttons in matlab automatically generated script, so I put the my radiobuttons code inside a function that is called by a listbox callback. Now is issue is, when I make a new selection in the radiobuttons group, my GUI only updates after I re-select what is selected earlier in the listbox.
How can I better incorporate the radiobutton code with my m-file in this case? I want my GUI to update whenever I make a new selection in the button groups... Thank you for reading, I really appreciate it!
採用された回答
Geoff Hayes
2016 年 8 月 9 日
chlor - in the GUI GUIDE editor, right-click on the radio button group to bring up its pop-up menu. Select *View Callbacks -> SelectionChangeFcn*. This will put that callback within your *.m file. This callback will fire whenever you select a radio button from within this group.
12 件のコメント
Thank you Geoff! I used this callback and initiated my button selection in the OpeningFcn as:
(since I have a listbox that takes the output of my buttongroup to generate a plot)
set(handles.buttongroup,'SelectedObject',handles.button1)
however, it gives me error that handles.read is non-exist field
so I tried to add this in my listbox callback
handles.read = get(handles.buttongroup, 'SelectedObject')
But it gives me the new error:
Cell contents reference from a non-cell array object.
Am I doing something wrong here? Can you please also give me a little advice on how to fix my code here? I just started learning to use buttongroup and I really appreciate your comment!!
Adam
2016 年 8 月 9 日
The line
set(handles.buttongroup,'SelectedObject',handles.button1)
can't possibly be giving an error related to handles.read being a non-existent field as it isn't attempting to access that field. It might be easier to post all relevant code.
function plot_OpeningFcn(hObject, eventdata, handles, varargin)
set(handles.buttongroup,'SelectedObject',handles.button1)
%something
guidata(hObject, handles);
function buttongroup_SelectionChangeFcn(hObject, eventdata, handles)
Mode = get(handles.buttongroup, 'SelectedObject');
View = get(Mode, 'String');
switch View
case 'View Type 1'
hi = handles.hi;
case 'View Type 2'
hi = handles.hi;
%do something to "hi"
hi=new_hi;
end
hi = handles.read %assign "hi" to new handle "handles.read" that will be used in listbox_Callback to pass down to func1(handles)
guidata(hObject, handles);
function listbox_Callback(hObject, eventdata, handles)
listbox_index=get(hObject, 'Value');
switch listbox_index %this creats "handles.hi" that will be used as input for buttongroup_SelectionChangeFcn
case 1
%do something
handles.hi=hi;
case 2
%do something else
handles.hi=hi;
end
handles.read = get(handles.buttongroup, 'SelectedObject')
func1(handles); %func1 is another function that I created use input "handles.read"
guidata(hObject, handles);
chlor thanks
2016 年 8 月 9 日
編集済み: chlor thanks
2016 年 8 月 9 日
Thanks for commenting Adam, I apologize if the code I posted is confusing, I try to simplify the code to make easier read, I hope this explains what you were asking...
Adam
2016 年 8 月 9 日
This line seems odd, especially its seemingly doing the opposite to what the comment says it is:
hi = handles.read %assign "hi" to new handle "handles.read" that will be used in listbox_Callback to pass down to func1(handles)
handles.read will presumably not exist at the point unless the listbox has been interacted with.
chlor thanks
2016 年 8 月 9 日
編集済み: chlor thanks
2016 年 8 月 9 日
Silly me! I changed the hi = handles.read to handles.read = hi, now it is only giving me the error
Cell contents reference from a non-cell array object.
Would this be the way I get "handles.read" in function listbox_Callback is inappropriate? The "handles.read" I am trying to get should be a cell array of strings.
chlor thanks
2016 年 8 月 9 日
編集済み: chlor thanks
2016 年 8 月 9 日
Sorry to bother you again. This is my current code for the buttongroup Callback if it may be the issue that I have not been able to figure out...
function buttongroup_SelectionChangeFcn(hObject, eventdata, handles)
a = handles.a;
b = handles.b;
Mode = get(handles.buttongroup, 'SelectedObject');
View = get(Mode, 'String');
switch View
case 'View Type 1'
set(handles.T2, 'Value', 0)
set(handles.T3, 'Value', 0)
hi = handles.hi; %"handles.hi" is taken from listbox Callback
case 'View Type 2'
set(handles.1, 'Value', 0)
set(handles.3, 'Value', 0)
hi = handles.hi;
x = false(size(hi));
for n=1:numel(a)
x = x | cellfun(@isempty,strfind(hi,a{n}));
end
hi(x) = [];
case 'View Type 3'
set(handles.1, 'Value', 0)
set(handles.2, 'Value', 0)
hi = handles.hi;
x = false(size(hi));
for n=1:numel(b)
x = x | cellfun(@isempty,strfind(hi,b{n}));
end
hi(x) = [];
end
handles.read = hi
guidata(hObject, handles);
Image Analyst
2016 年 8 月 9 日
Are you trying to use the "read" field of handles as a global variable? Or is "read" the tag of some other control. Why do you think it should have a value before you ever start using it? It only will have a value if you have a control called "read", not if you're using it as a global variable but never assigned anything to it.
chlor thanks
2016 年 8 月 9 日
I am trying to assign the cell array "hi" to "handles.read" as a global variable that can be shared by all other callbacks. I have done similar things in other Callbacks and it has worked... Now I am confused again...
Image Analyst
2016 年 8 月 9 日
What about the first time through, when handles.hi does not have a value yet and you try to use it? Also, you should initialize hi just in case none of the switch cases are met.
chlor thanks
2016 年 8 月 9 日
I am posting a new question http://www.mathworks.com/matlabcentral/answers/299055-listbox-buttongroup-callbacks-error-in-guide-made-gui
I apologize that I kept the thread so long... Thank you all for commenting under my thread and kept me going and wondering!!
chlor thanks
2016 年 8 月 10 日
編集済み: chlor thanks
2016 年 8 月 10 日
Sorry! I didn't see your comment earlier, Image Analyst. Do you mean handles.hi created in listbox_Callback? I believe it has a value, because I tried to skip the buttongroup_SelectionChangeFcn and use handles.hi directly and it hass been working fine with no errors. The issue starts after I try to use buttongroup_SelectionChangeFcn to further categorize handles.hi into handles.read and pull the new variable handles.read back into listbox_Callback for func1.
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Creating, Deleting, and Querying Graphics Objects についてさらに検索
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の MathWorks のサイトは、お客様の地域からのアクセスが最適化されていません。
南北アメリカ
- América Latina (Español)
- Canada (English)
- United States (English)
ヨーロッパ
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
