原创 Debugging MATLAB Programs

2010-5-20 18:43 3380 11 11 分类: 处理器与DSP
If the variable names seem to be correct and the input data is correct,then you are probably dealing with a logical error.You should check each of your assignment statement.

1.If an assignment statement is very long,break it into several smaller assignment statements.Smaller statements are easier to verify.

2.Check the placement of parentheses in your assignment statements.It is a very common error to have the operations in an assignment statement evaluated in the wrong order.If you have any doubts as to the order in which the variables are being evaluated ,add extra sets of parentheses to make your intentions clear.

3.Make sure that you have initialized all of your variables properly.

4.Be sure that any functions you use are in the correct units.For example,the input to trigonometric functions must be in units of radians,not degrees.

If you are still getting the wrong answer,add output statements at various points in your program to see the results of intermediate calculations.If you can locate the point where the calculations go bad,then you know just where to look for the problem,which is 95% of the battle.

If you still cannot find the problem after taking all of these steps,explain what you are doing to another student or to your instructor,and let them look at the code.It is very common for a person to see just what he or she expects to see when they look at their own code.Another person can often quickly spot an error that you have overlooked time after time.


From the Book of 《MATLAB Programming for Engineers》

PARTNER CONTENT

文章评论0条评论)

登录后参与讨论
EE直播间
更多
我要评论
0
11
关闭 站长推荐上一条 /3 下一条