How to run and analyze a big Matlab class code line by line.
12 ビュー (過去 30 日間)
古いコメントを表示
I am new to Matlab classes and I am working on a big Matlab class (600+ lines in total) where I need to check outcome from each executable line in terms of variables being used and returned and their size, type etc. so that I can remove unnecessary variables and preallocate all necessary variables. I tried putting break points but it seems that Matlab goes upto end of methods and not beyond that where actual work starts. I am aware of mlint, tic-toc and profiler for optimizing Matlab codes but for that I need to run the whole thing first. Can anyone please let me know if it is posssible at all to run a Matlab class with breakpoints?
2 件のコメント
Geoff Hayes
2014 年 5 月 24 日
Yes, it is possible to put breakpoints in a class definition and have the code break in the appropriate place. I often do this.
Note that if you ever change the code, then you must run clear all to refresh the class definition. Maybe that is why you are having problems - changes are being made to the class definition, a new instance of that class is created using the old definition and stepping through the code is confusing.
Cedric
2014 年 5 月 24 日
編集済み: Cedric
2014 年 5 月 24 日
Note that e.g.
clear all
clears all break points. Therefore, if you have a script in which you create an object based on a classdef which contains break points, if the script starts will clear all, your break points are gone. So keep in mind that you may have to comment out a few calls to clear before you run the script.
採用された回答
James Kristoff
2014 年 5 月 24 日
You can place a breakpoint at any point that you would like to ensure you stop at. I am not sure what you mean about work starting after the end of the function. In a MATLAB class, all 'work' happens inside of the class's methods. If, for example you have the following class:
classdef foo < handle
properties
bar
end
methods
% class constructor
function obj = foo(obj)
obj.bar = 'hello';
% do some work
obj.doWork();
end
function doWork(obj)
disp(obj.bar);
end
end
end
and you then want to see how this class works you can put a breakpoint on the line:
obj.bar = 'hello';
and the execute the command:
aFooObject = foo;
in MATLAB®. This should stop at the breakpoint, and then you can step through the code using the F10 key (in Windows). When you get to the line:
obj.doWork();
you can step into this function using the F11 key (in Windows), which will allow you to debug the doWork() function as well.
0 件のコメント
その他の回答 (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!