Displaying MATLAB output in linux terminal

17 次查看(过去 30 天)

I am running a MATLAB script in the background using the command line:

nohup matlab -nodisplay < scriptname.m > /dev/null &

The script integrates an ODE with N sets of different initial conditions, i.e. it loops N times. It takes days to run so I would like to output the progress, say every 10% completion. I've written a simple if statement:

if mod(n_th_loop,complete_out) == 0
  fprintf('%2.2f %% complete', 100*n_th_loop/N);
end

When running the script inside MATLAB, the percentage completion is printed out as I intended. However, I cannot get anything to print out into the linux terminal when I run the script in the background. I have also tried using disp(...), but have exactly the same problem.

Is there any way to run a MATLAB script in the background, but print messages to the linux terminal?

Thanks, James

采纳的回答

Kevin Claytor
Kevin Claytor 2016-2-25
Pardon my *nix ignorance, but doesn't the & command spin off the process in a new terminal? If so it's probably dumping the messages there.
You could just start a screen session and flip back to it to check on the status.
When I was running on a cluster, I'd dump messages to a temporary file;
fid = fopen(sprintf('ODE_run%d.tmp', runnum));
fprintf(fid, 'msg');
fclose(fid);
and have it e-mail me when done.
  1 个评论
James Wright
James Wright 2016-2-25
Your solution didn't quite solve my problem, but prompted me to try:
fid = fopen('PercentComplete.dat','w');
fprintf(fid,'%2.2f%%Complete', 100*n_th_loop/N);
fclose(fid)
Which does more or less what you described and works fine. Thanks.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Debugging and Analysis 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by