dbup does not behave as expected
    5 次查看(过去 30 天)
  
       显示 更早的评论
    
In MATLAB '25.1.0.2943329 (R2025a)', when in debug mode, calling dbup within a function behaves differently from calling dbup directly.
Save the following code as test_bug1:
function test_bug1(a,b)
c = a + b;
end
First, run 
dbstop if error,
then call 
test_bug1([1 2 3], [2 3]);
This will enter debug mode at the line c = a + b inside the test_bug1 function.
Executing dbup at this point behaves as expected and returns to the previous workspace.
However, if you define the following function:
function dbup_1()
dbup;
end
Executing dbup_1 at that moment results in an error, indicating that the current command is not a debugging command.
Similarly, if you create the following script and save it as dbup_2:
dbup;
Calling dbup_2 still results in the same error.
My question is: What causes the issue above?
If I want to include dbup, dbdown, and similar commands inside a function, how should I proceed?
2 个评论
  Adam Danz
    
      
 2025-5-29
				Accessing variables from a different workspace usually it not a good idea.  What's the ultimate goal?  Why can't it be realized by passing variables into the function?  
采纳的回答
  Matt J
      
      
 2025-5-29
        
      编辑:Matt J
      
      
 2025-5-29
  
      There are special limitations on dbup, dbdown, and friends. You cannot call them from functions, because when a function is executing, you are not in debug mode anymore.
3 个评论
  Adam Danz
    
      
 2025-5-29
				This is documented in the dbup page, "dbup can only be called from the command line."
更多回答(0 个)
另请参阅
类别
				在 Help Center 和 File Exchange 中查找有关 Debugging and Analysis 的更多信息
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!



