GUI-Function inside the Radio button function

In GUI I created the attached function called BE_RE(X1,N1) and I would like to call it inside the radiobuttons. It gives me the following error:
??? Undefined variable "handles" or class "handles.axes1".
Error in ==> BE_RE at 37
PK1=plot(X1(:,1),X1(:,7),'-sc','LineWidth',2,'parent',handles.axes1) % McMaster
Error in ==> BE>radiobutton5_Callback at 124
BE_RE(num, Data_Nr)
Error in ==> gui_mainfcn at 96
feval(varargin{:});
Error in ==> BE at 42
gui_mainfcn(gui_State, varargin{:});
Error in ==> guidemfile>@(hObject,eventdata)BE('radiobutton5_Callback',hObject,eventdata,guidata(hObject))
??? Error while evaluating uicontrol Callback

 Accepted Answer

If the variable "handles" is not known inside this function, provide it as input:
function BE_RE(X1,N1, handles)
Now add the handles struct inside the calling function also, which is the radio button's callback:
function RadioCallback(hObject, EventData)
handles = guidata(hObject);
BE_RE(X1,N1, handles)

7 Comments

Thanks a lot Jan Simon. Now the function is working. However, I still have another problem. The multiplot at the same figure is not working. I used the following code inside the BE-RE(X1,N1, handles) function
.....
elseif N1==13
BE1=plot(X1(:,1),X1(:,3),'-ok','LineWidth',2,'parent',handles.axes1);hold on; % Bearden
BE2=plot(X1(:,1),X1(:,4),'-+b','LineWidth',2,'parent',handles.axes1); % Siegbahn
BE3=plot(X1(:,1),X1(:,5),'-*g','LineWidth',2,'parent',handles.axes1); % Scofield
BE4=plot(X1(:,1),X1(:,6),'-xr','LineWidth',2,'parent',handles.axes1); % Chantler
BE5=plot(X1(:,1),X1(:,7),'-sc','LineWidth',2,'parent',handles.axes1); % McMaster
BE6=plot(X1(:,1),X1(:,8),'-dm','LineWidth',2,'parent',handles.axes1); % Elam
BE7=plot(X1(:,1),X1(:,9),'-^y','LineWidth',2,'parent',handles.axes1); % Yeh& Lindau
BE8=plot(X1(:,1),X1(:,10),'-vk','LineWidth',2,'parent',handles.axes1); % Nefodov
BE9=plot(X1(:,1),X1(:,11),'->b','LineWidth',2,'parent',handles.axes1); % Cardona & Ley
BE10=plot(X1(:,1),X1(:,12),'-<g','LineWidth',2,'parent',handles.axes1); % Henke
BE11=plot(X1(:,1),X1(:,13),'-pr','LineWidth',2,'parent',handles.axes1); % Verner
BE12=plot(X1(:,1),X1(:,14),'-hc','LineWidth',2,'parent',handles.axes1); % Williams
legend('Bearden','Siegbahn','Scofield','Chantler','McMaster','Elam',...
% 'Yeh& Lindau','Nefodov','Cardona & Lee', 'Henke', 'Verner','Williams')
xlabel('Atomic Number');ylabel('Binding Energy, keV'); hold off;
end
Then please explain with details, what "not working" means.
I am trying to have multi curves in the same figure. So I plot the first x,y data (X1(:,1), X1(:,3)). Then I hold on and plot further curves but I did not get the multicurves.
What do you get instead?
I have got only the plot of the last curve, but I need to have all curves together at the same figure. Thanks for your kind assistance
Did you use hold on already?
Yes, I used it after plotting the first curve.

Sign in to comment.

More Answers (0)

Categories

Community Treasure Hunt

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

Start Hunting!