Matlab help

Discussion in 'Programmer's Corner' started by Marie, Feb 19, 2008.

  1. Marie

    Thread Starter Member

    Nov 20, 2007
    24
    0
    Hi,

    I'm trying to write a Matlab program with the following objective: determine the effect of phase error in the resulting current obtained from
    sin(nwt)-sin(nwt+phi).

    I've managed to write a program where i can see the effect of increasing values of phi=phase error, However, i'm am unable to generate a graph showing the max value of residual current for different phase error.

    The problem that the program is a loop and i'm unable to save the max value for each phase error. The value which remains each time is the last value.

    I'm wondering if there is a way such as in C where u can defined the size of an array to store data for each loop increment. I've tried to use save but i still get the value from the last iteration. Is there any way to recover the data from each iteration.

    I've attached the mfile I'm using.

    Thanks.
     
  2. Dave

    Retired Moderator

    Nov 17, 2003
    6,960
    144
    You could saddle the code with a further for-loop:

    Code ( (Unknown Language)):
    1. for phase=[0:5:180]  
    2.    
    3.     wt=[0:10:180];
    4.    
    5.     for n = 1:size(x)             % I don't know what the size of x is
    6.     Il=sind(n*wt);      %actual current
    7.     Ic=sind(n*wt+phase);    %Current with phase error
    8.  
    9.     res=Il-Ic;               %residual current
    10.    
    11.     x(n)=max(res);               % Now has the increment variable i to prevent overwriting
    12.            
    13.     plot(wt,res)
    14.     grid
    15.     pause
    16.     end    
    17.  
    18. end
    This code won't work, it is just a demonstration of how you would do it using a saddled for-loop and variable n.

    The problems I see are the plot instruction which is, as far as I can see, misplaced. Furthermore, the saddled loop requires a limiter, not just size(x).

    Dave
     
  3. Marie

    Thread Starter Member

    Nov 20, 2007
    24
    0
    Hi,

    Thanks a lot. I'm going to try it.
     
Loading...