Similar lines are much different in time for run due to MATLAB profiler.
    4 views (last 30 days)
  
       Show older comments
    
The right hand side of all of below equation are numbers (in same order of magnitude) but the first line is much slower. Any idea why this is happening? The image of profile is also attached.
% Comp.Yp(j,1)=Yp;
% Comp.Yp1(j,1)=Yp1;
% Comp.Yp2(j,1)=Yp2;
% Comp.Yt(j,1)=Yt;
% Comp.Y_sh(j,1)=Y_sh;
% Comp.Y_Ex(j,1)=Y_Ex;
3 Comments
  Philip Borghesani
 on 20 Jan 2022
				You are calling this funciton quite a few times.  Without more understanding of your code it is unlikely that a good anwer can be supplied.  Some questions and things to think about:
- Is your object a handle or value object? If it is simple give some info about it or the code.
- How are you calling this function? what are the inputs and outputs?
- Are your members (Yp1,Yp2,...) preallocated?
Most likely the best way to improve your code is to restructure it so that the helper function can be vectorized and not called so many times.
Answers (2)
  Fangjun Jiang
      
      
 on 13 Jan 2022
        It takes time to create "Comp" as a structure. Add the line below first and then profile again.
Comp=struct;
  Philip Borghesani
 on 20 Jan 2022
        Most likely this is happining due to memory allocation, caching and array growth.  Unfortunatly this answer wont help you much.... See my comments to your question
0 Comments
See Also
Categories
				Find more on Function Creation in Help Center and File Exchange
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


