user466534
user466534

Reputation:

simulate sinusodial graphs in matlab

My today's question is how to simulate continuously some graph in matlab? For example: let us consider the following simplest code

x = 0 : 0.1 : 10;
z = sin(x);
plot(x,z), grid

When I run this code, I get usually sin function graph, whose figure is given below enter image description here

Actually, what I need is, that the graph is static, i.e. that it does not move. What I want is that simulate this graph, namely appears on window, disappears and then again repeat this procedure, as I guess I need loop for this, but maybe there is some built-in function for simulation graphs in matlab? Please help me

Upvotes: 0

Views: 184

Answers (1)

Eitan T
Eitan T

Reputation: 32920

Do you mean that you want to animate this graph? MATLAB offers numerous ways to do that.

One of the simplest would be generating a short movie frame-by-frame using getframe and then playing it with the movie command. For example:

%// Generate movie
x = 0:0.1:10;
FRAMES = 32;                  %// Total number of frames
for k = 1:FRAMES
    ph = k * 2 * pi / FRAMES; %// Accumulate phase
    plot(x, sin(x + ph))      %// Generate plot
    grid, axis equal
    M(k) = getframe;          %// Capture frame
end

%// Play movie 10 times
movie(M, 10)

Upvotes: 1

Related Questions