MATLAB How to do a dynamic graph in matlab

AI Thread Summary
The discussion focuses on creating a dynamic graph in MATLAB that transitions through different trigonometric functions: Sin(x), Cos(x), and Tan(x) over the interval from 0 to 3π. The user initially struggled with MATLAB but eventually shared a solution for a continuously changing sine plot using a function handle and a loop. The provided code utilizes a nested for loop to update the plot in real-time, incorporating a pause to visualize the changes. The approach demonstrates the use of MATLAB's plotting capabilities effectively. This solution may assist others looking to create dynamic visualizations in MATLAB.
juanitotruan77
Messages
44
Reaction score
0
Hi guys, so I've never used MATLAB before, and i need to make a plot that changes constantly.
Let's say that i have Sin(x) from 0 to 3pi
Then i need it to change to a Cos(x) from 0 to 3pi
then to a Tan(x).

I could do it in other languaje like Php or c, but in MATLAB i have no idea. I think it can be made with a for cycle nested inside of another for cycle.
 
Physics news on Phys.org
Nevermind, i got it. What i really wanted was a changing sin plot. I'm going to leave it here in case anyone needs it.
Code:
f = @(x,t) 1.5*sin(10*x-5*(t/10));
linkdata on
hold on;
for t=1:50
    xi = -3*pi:pi/1000:pi;
    plot(f(xi,t));
    pause(.1);
clf('reset')
end
 
Last edited:
Very cool!
 
kreil said:
Very cool!

Thanks (:
 

Similar threads

Replies
5
Views
3K
Replies
5
Views
2K
Replies
1
Views
2K
Replies
4
Views
2K
Replies
4
Views
2K
Replies
22
Views
4K
Back
Top