0

I have a function file which contains a GUI.

Whenever I run (compile) the file using the green run logo in MATLAB it successfully builds. Whenever I try to run it from the command window i.e: run(MyFile);I get this error but the file still builds correctly:

??? Error using ==> fileparts at 31
Input must be a row vector of characters.

Error in ==> run at 25
[p,s,ext] = fileparts(script);

I'm not getting the error when I hit 'run' in the text editor.

Thoughts?

5
  • try dbstop if error and check what datatype script is. Commented Dec 19, 2013 at 22:29
  • 31 error(message('MATLAB:fileparts:MustBeChar')); Was what I got when I typed: dbstop if error; run(MyFile); in the command window Commented Dec 19, 2013 at 22:31
  • If matlab stops at the error, check what script is. Should be some file path (char) Commented Dec 19, 2013 at 22:33
  • What do you mean by check what script is? Sorry, new to MATLAB. Where would I look? Commented Dec 19, 2013 at 22:35
  • you could simply type whos script at the command line Commented Dec 19, 2013 at 22:42

1 Answer 1

1

It should work this way:

runtmp = fullfile('foldername','filename.m');
run(runtmp);

notice that the 'run' command executes scripts not currently on the MATLAB path. However, you should use cd or addpath to navigate to or to add the appropriate folder, making a script executable by entering its name alone. The other point is run changes to the folder that contains the script, executes it, and resets back to the original folder. If the script itself changes folders, then run does not revert to the original folder, unless scriptname changes to the folder in which this script resides.

for more information check here.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.