Complaint from a matlab user about Operation termination!!

When I have run the matlab for a while, I terminated the program since I found a bug. Then nothing appeared in the workspace. I believe it is not a convenient way. I should check some data when I terminated at the same time. The only way is to trace some data into a file when the program begins. sigh

 Réponse acceptée

Give the command
dbstop if error
before you run. Then, if you encounter an error message or press control-c, the program will stop at the current line and allow you to examine variables.

6 commentaires

Have you ever checked? There is noting in the workspace. How can I examine variables? That is what I said: bad design!
if no variables exist then your code must have crashed on the 1st line in that function. Look at lasterror to provide information on what the error was.
Yes, I have checked; I have used this many times over the years.
write a function named aa in your matlab:
function a = aa
for i = 1:2147483647
a = i + 2;
end
Then type aa in the command widow. Use control+C to termined. You will find there is noting in the workspace of matlab.
However, if just type the funciton in command window, ctrl + c can save some variables in the workspace. I don't know what is the reason?
Sean de Wolski
Sean de Wolski le 21 Déc 2011
Modifié(e) : Stephen23 le 16 Nov 2015
Coping your above 'aa' function and setting >> dbstop if error before I run it, when I hit crtl+c (Windows) as fast as I can:
a = 138949749 i = 138949751
Thans a lot! dbstop if error is useful! Forgive my rude!

Connectez-vous pour commenter.

Plus de réponses (2)

Jan
Jan le 21 Déc 2011

2 votes

I agree the program you are using has a bad design. If it is a function and you have to terminate it by Ctrl-C, all performed work is lost.
I assume the programmer did not expect the user to kill the process. If a premature program termination can be expected, a GUI containing a "Terminate" button should offer a clean way to stop the execution. The program has to check the status of the button (or use any other method for message passing) and reply and useful data after cleaning up.
I do not understand, why you ask this here. Contacting the author of the program will be more helpful. Ask for an improved usability, especially some progress information and the possibility for a premature termination.
Be aware, that it is impossible for Matlab to perform all required and wished tasks automagically for you, because Ctrl-C is the brute way to stop all executions. Even a smart cleanup would be interupted!

2 commentaires

write a function named aa in your matlab:
function a = aa
for i = 1:2147483647
a = i + 2;
end
Then type aa in the command widow. Use control+C to termined. You will find there is noting in the workspace of matlab.
However, if just type the funciton in command window, ctrl + c can save some variables in the workspace. I don't know what is the reason?
Look in the MATLAB help under "scope"

Connectez-vous pour commenter.

kumar verma
kumar verma le 16 Nov 2015
Modifié(e) : Walter Roberson le 16 Nov 2015

0 votes

wtf...when im typing sin(pi) im getting ans as 1.2246e-16 fine ..later i tried if x 0:pi/2:pi sin(x) i got ans 0 1 0......why ...wats the problem....should i write exam or not...plzz help me.... literally suffering a lot because of this problem...today 14:00 i should give my paper,... please reply asap...
thanks in advance

1 commentaire

>> x = 0:pi/2:pi; sin(x)
ans =
0 1 1.22464679914735e-16
This is due to the fact that pi cannot be exactly represented in binary floating point numbers. However, you will find that sind(180) is 0 exactly because 180 is exactly representable in binary floating point and sind() checks for the multiples of 90 as a special case.
If you happened to work symbolically,
x = sym('pi'); sin(x)
then you would get 0 exactly because the symbolic toolbox is not limited to binary floating point numbers.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Entering Commands dans Centre d'aide et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by