How can I understand that my program is running or not?

64 visualizaciones (últimos 30 días)
Sunipa Som
Sunipa Som el 29 de Jul. de 2024
Comentada: Sunipa Som el 1 de Ag. de 2024
My one matlab program is running. It is not showing any error, but taking too long time. I have checked it with breakpoints. Is there any way to understand that Matlab is running or not?
  2 comentarios
Aquatris
Aquatris el 29 de Jul. de 2024
Matlab window left bottom corner would read 'busy' when it is doing stuff.
If it is taking too long and you want some indication of your code still doing what it is supposed to do instead of getting stuck in an infinite loop, you can use waitbars or fprintf statements in various locations of your code to trace it from the console/popup windows.

Iniciar sesión para comentar.

Respuesta aceptada

R
R el 29 de Jul. de 2024
You can use a few methods to determine if your MATLAB program is still running:
  • Command Window Output: You can add periodic disp or fprintf statements in your code to print messages or progress updates to the Command Window. This will help you see if MATLAB is progressing through your code.
  • Progress Bar: Use MATLAB's built-in waitbar function to display a progress bar.
% Sample long-running MATLAB script with progress bar
% Number of iterations (this will take some time to complete)
numIterations = 1e7;
% Initialize the waitbar
h = waitbar(0, 'Please wait...');
% Start the timer
tic;
% Perform a large number of computations
result = 0;
for i = 1:numIterations
% Simulate a computational task
result = result + sin(i) * cos(i);
% Update the progress bar every 100,000 iterations
if mod(i, 1e5) == 0
waitbar(i / numIterations, h, sprintf('Progress: %d%%', round(i / numIterations * 100)));
end
end
% Close the waitbar
close(h);
% Stop the timer and display the elapsed time
elapsedTime = toc;
fprintf('Elapsed time: %.2f minutes\n', elapsedTime / 60);
% Display the final result (to prevent optimization from removing the loop)
disp(result);
  • Profiling: Use the MATLAB Profiler to analyze the performance of your code and identify any bottlenecks.
profile on;
% Your code here
profile off;
profile viewer;
  • Task Manager/Activity Monitor: On Windows, you can open the Task Manager (Ctrl + Shift + Esc) and look for the MATLAB process to see if it is using CPU resources. On macOS, use the Activity Monitor.
  • Checking Variables: Use the whos command to check the workspace variables and their sizes periodically. This can help you understand if MATLAB is processing data.
for i = 1:1000
% Your code here
if mod(i, 100) == 0
whos;
end
end
By using these methods, you can better understand whether your MATLAB program is still running and making progress.
  4 comentarios
Aquatris
Aquatris el 31 de Jul. de 2024
What kind of information are you looking for? Seeing Busy already indicates some code is running.
And to my knowledge, no, if you see busy, Matlab will not execute any commands you type until after the busy state is over, which is after it finishes running the code.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre App Building en Help Center y File Exchange.

Productos


Versión

R2015a

Community Treasure Hunt

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

Start Hunting!

Translated by