Matlab help

Thread Starter

Marie

Joined Nov 20, 2007
24
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.
 

Attachments

Dave

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

Rich (BB code):
for phase=[0:5:180]  
    
    wt=[0:10:180];
    
    for n = 1:size(x)             % I don't know what the size of x is
    Il=sind(n*wt);		%actual current
    Ic=sind(n*wt+phase);	%Current with phase error

    res=Il-Ic;	             %residual current
    
    x(n)=max(res);               % Now has the increment variable i to prevent overwriting
    		
    plot(wt,res)
    grid
    pause
    end    

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
 
Top