How to run and analyze a big Matlab class code line by line.
    6 vues (au cours des 30 derniers jours)
  
       Afficher commentaires plus anciens
    
    Arti Siddhpura
 le 23 Mai 2014
  
    
    
    
    
    Réponse apportée : James Kristoff
    
 le 24 Mai 2014
            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 commentaires
  Geoff Hayes
      
      
 le 24 Mai 2014
				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
      
      
 le 24 Mai 2014
				
      Modifié(e) : Cedric
      
      
 le 24 Mai 2014
  
			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.
Réponse acceptée
  James Kristoff
    
 le 24 Mai 2014
        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 commentaires
Plus de réponses (0)
Voir également
Catégories
				En savoir plus sur Function Creation dans Help Center et File Exchange
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!



