Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

running the user selected .m file in the pushbutton callback

Asked by pammy on 3 Jul 2013

on push button number 1 i wrote the code to browse the . m file like this:

handles.output = hObject;
[fn pn] = uigetfile('*.m','select your file');
complete=[pn fn];
set(handles.edit11,'string',complete);
handles.fn=fn;
set(handles.edit12,'string',fn);
guidata(hObject,handles);

on push button 2 i.e running the selected file i wrote the code like this:

handles.output = hObject;
fn=handles.fn;
fn;
guidata(hObject,handles);

it does not produces any output...

if the select the file named count.m and in pushbutton 2 i simply wrtite count

then it'll execute and give me the results but when i want to generalize it like i said above, the output is not shown.. can u tell me whats is the problem in it....

0 Comments

pammy

Products

No products are associated with this question.

1 Answer

Answer by Guru on 3 Jul 2013
Edited by Guru on 3 Jul 2013
Accepted answer

Umm, by what I am guessing you are trying to do in your push button 2 callback is that you want to run the file that was selected.

fn is a variable that contains a char array of the file name selected with the .m extension. Simply stating a variable in MATLAB would display this if you did not have the semicolon "fn;"

However to execute the file name in MATLAB you can use the "run" command

run(fn);

In short, the line of code that reads:

fn;

should be changed to:

run(fn);

HTH!

3 Comments

pammy on 3 Jul 2013

gives me the error as shown below.

 what it does is it says undefined variable to the name of the .m file... that is , if my file is color.m then it says  
   undefined variable color or class color.m

if my file is extractBlock.m then it shows the error

undefined variable extractBlock or class extractBlock.m and so on...

can u tell me what can i do now?

Undefined variable "extractBlock" or class "extractBlock.m".

Error in run (line 74) evalin('caller',[script ';']);

Error in copyMoveToolDummy>pushbutton6_Callback (line 775) run(f);

Error in gui_mainfcn (line 96) feval(varargin{:});

Error in copyMoveToolDummy (line 42) gui_mainfcn(gui_State, varargin{:});

Error in @(hObject,eventdata)copyMoveToolDummy('pushbutton6_Callback',hObject,eventdata,guidata(hObject))

Error while evaluating uicontrol Callback

pammy on 3 Jul 2013

it works what i did is i simply changed the fn to pn that i provide the whole path to the file name then it works good....

thank u so much....

Guru on 3 Jul 2013

Ahh yes. The solution I gave above assumes that the path location of the file is on the matlab path already. But yes, including the full path in your function call would run. You can also add the pn to the matlab path with

addpath(pn)

if that was intended.

Edit: changing original post to make use of the code markup text.

Guru

Contact us