How to do a dynamic graph in matlab

  • Context: MATLAB 
  • Thread starter Thread starter juanitotruan77
  • Start date Start date
  • Tags Tags
    Dynamic Graph Matlab
Click For Summary

Discussion Overview

The discussion centers around creating dynamic plots in MATLAB, specifically focusing on how to animate a sine function over time. Participants explore the implementation details and share code snippets related to this task.

Discussion Character

  • Exploratory, Technical explanation, Homework-related

Main Points Raised

  • One participant expresses a need to create a constantly changing plot in MATLAB, initially considering using nested for loops to achieve this.
  • Another participant shares a solution for animating a sine plot using a function definition and a loop, providing specific MATLAB code for implementation.
  • Subsequent replies express appreciation for the shared solution.

Areas of Agreement / Disagreement

Participants generally agree on the approach to creating a dynamic plot, with one participant successfully implementing a solution and others expressing positive feedback.

Contextual Notes

The discussion does not address potential limitations of the provided code or any assumptions regarding the MATLAB environment or version compatibility.

Who May Find This Useful

Individuals interested in MATLAB programming, particularly those looking to create dynamic visualizations or animations in their plots.

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:
kreil said:
Very cool!

Thanks (:
 

Similar threads

  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 5 ·
Replies
5
Views
4K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 11 ·
Replies
11
Views
3K
  • · Replies 5 ·
Replies
5
Views
4K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 22 ·
Replies
22
Views
4K
  • · Replies 1 ·
Replies
1
Views
3K