script doesn't run from gui
Show older comments
I created a script called v1s, if I run that scrip from command windows, that script run excellent , but if I calle that script from a GUI (boton funtion) in the command windows appears the following:
Undefined variable "v1s" or class "v1s.m".
Error in Principal>pushbutton2_Callback (line 88)
v1s.m
Error in gui_mainfcn (line 96)
feval(varargin{:});
Error in Principal (line 42)
gui_mainfcn(gui_State, varargin{:});
Error in @(hObject,eventdata)Principal('pushbutton2_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating uicontrol Callback
I want know how call a script from a button funcion in a GUI
v1s script is:
v6(TbDate,vib1pp,TbDate(vib1pp>ppmax),vib1pp(vib1pp>ppmax),TbDate,vib1ap,TbDate(vib1ap>5),vib1ap(vib1ap>5),TbDate,vib1pd,TbDate(vib1pd>45),vib1pd(vib1pd>45),TbDate,vib1ad,TbDate(vib1ad>20),vib1ad(vib1ad>20),TbDate,vib1pf,TbDate(vib1pf>85),vib1pf(vib1pf>85),TbDate,vib1af,TbDate(vib1af<80),vib1af(vib1af<80))

if a pass all the value from GUI my graph is wrong.
% --- Executes on button press in pushbutton2.
function pushbutton2_Callback(hObject, eventdata, handles)
global TbDate vib1pp vib1ap vib1pd vib1ad vib1pf vib1af ppmax
v6(TbDate,vib1pp,TbDate(vib1pp>ppmax),vib1pp(vib1pp>ppmax),TbDate,vib1ap,TbDate(vib1ap>5),vib1ap(vib1ap>5),TbDate,vib1pd,TbDate(vib1pd>45),vib1pd(vib1pd>45),TbDate,vib1ad,TbDate(vib1ad>20),vib1ad(vib1ad>20),TbDate,vib1pf,TbDate(vib1pf>85),vib1pf(vib1pf>85),TbDate,vib1af,TbDate(vib1af<80),vib1af(vib1af<80))

Answers (1)
You should call the script my its name without '.m' attached i.e. just
v1s
not
v1s.m
The script will run in the scope of the pushbutton callback, whether that is what you want or not I don't know.
4 Comments
Alejandro Franco
on 4 Mar 2015
Adam
on 4 Mar 2015
I can't see any plotting functions in your script, but any plotting instructions there are should refer to explicit axes to ensure your plot is in the right place.
As for the variables, as i mentioned, the script is run within the scope of your pushbutton callback therefore the variables are in that scope and go out of scope when the callback ends. They never appear in the base workspace.
I have never had requirement personally to have a GUI front end to something, but have the variables appear in the base workspace, I always work with them under the GUI.
I think you can use the assignin function from your pushbutton callback if you really want the variables in your base workspace.
Ankit Singh
on 8 May 2016
but when we save them in work space
Image Analyst
on 8 May 2016
Edited: Image Analyst
on 8 May 2016
Ankit, that doesn't make sense - finish your sentence or expand on what you're saying.
Categories
Find more on Creating, Deleting, and Querying Graphics Objects in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!