MATLAB Answers

Function run(scriptname) doesn't work.

54 views (last 30 days)
LUONG Vuong-son
LUONG Vuong-son on 19 Nov 2019
Commented: Adam Danz on 21 Nov 2019
when i try to execute my script from command:
run('C:\Users\hello.m')
==> nothing happens (no error).
my script 'hello.m' is not executed. however, if i use matlab editor to run this script. It works.
Somebody can tell me why and help me figure out the solution, please!
when i use the commande "echo on all" to check.
normally it displays:
% Finally, evaluate the script if it exists and isn't a shadowed script.
evalin('caller', [script ';']);
***************************** hello ***********************
**************************** i am son*******
*********************************************************
*********************************************************
*****************************---------------*******************************
*********************************
*********************************
*********************************
delete(cleaner);
however, on my PC it displays:
% Finally, evaluate the script if it exists and isn't a shadowed script.
evalin('caller', [script ';']);
delete(cleaner);

  8 Comments

Show 5 older comments
Guillaume
Guillaume on 21 Nov 2019
What is the output of
which hello.m
  • when your current directory is C:\users\ (i.e. when you're running the script from the editor)?
  • when your current directory is whichever directory you're in when you're using the run command?
Are you sure that the actual script you're running is in C:\users\? This directory is not normally used to store matlab files and you shouldn't be putting files in there.
Does matlab tells you it needs to change directory when you run the script from the editor?
LUONG Vuong-son
LUONG Vuong-son on 21 Nov 2019
i have just add the command into script ('run.m') to check the log message.
% Finally, evaluate the script if it exists and isn't a shadowed script.
%disp(script);
evalin('caller', [script ';']);
delete(cleaner);
and now, it works. Really, i don't know why?
Adam Danz
Adam Danz on 21 Nov 2019
It was probably always working. For example, run this script and you'll see no evidence that it was executed.
t = 0;
x = t+9;

Sign in to comment.

Answers (1)

Jan
Jan on 21 Nov 2019
Store the M-files in a folder, in which you have full access. C:\Users\ is a bad idea. Create a folder somewhere else, e.g. inside your user folder, in the documents, on disk D, etc.
"Run function is always stubbed!" Is it? Then perhaps you have overwritten it? Check it:
which run -all
Check your script also:
which hello -all
type('C:\Users\hello.m') % Again: choose another folder
As said already, set a breakpoint in the code to check, if Matlab processes the assumed file at all.

  0 Comments

Sign in to comment.

Products


Release

R2016b