4
$\begingroup$

I have imported two .mat files from Matlab. One containing the x coordinates and another y of a curve at different instants. So the .mat files are matrix and each row belongs to coordinates at a given time. I am planning to make a movie in Mathematica using the Table command because Matlab movies are of poor quality and there is no way for antialiasing in Matlab.

I am using these on mathematica

X = Import["X.mat"];
Y = Import["Y.mat"];

Do[xx = X[[1, i]];
 yy = Y[[1, i]];
 data = Transpose@{xx, yy};
c[i] = ListPlot[data], {i, 1, 10, 1}];

I want to then put all the listplot in a table and generate an animation.

As an example: Suppose you have two matrices A and B given as: A = [1 2 3;4 5 6;7 8 9]; and B = [10 20 30;40 50 60;70 80 90]

Suppose the entry's of each row are points. I mean (1,1) (2,20) and so on are points. And each row belongs to some instant of time. So at every instant of time I have three points plotted on a figure. My question is how to combine the plots (3 in this case) in order to get a movie. What should be the right loop which does these:

  1. Selects values from the matrix A and B
  2. Then creates 3 points.
  3. Plots them.
  4. Combine the figures in a table or so for a movie.

I know that my loop construct is not correct. But I am at a loss that how I should do it. I have never used loops or arrays in Mathematica before. Please suggest how I should proceed. Thanks in advance.

$\endgroup$
  • $\begingroup$ How can I share my file? I get two matrices X and Y from Matlab code. Each row of the matrix has the x and y coordinates respectively at a given time. I can listplot the data of a given time. But i cannot create a table of plots for all the time instant by loop in mathematica $\endgroup$ – Brato Oct 2 '14 at 1:10
  • $\begingroup$ If you have an account with any cloud storage service. You can upload it there and give a link. $\endgroup$ – RunnyKine Oct 2 '14 at 1:17
  • $\begingroup$ Sorry I dont have such account. But I can pose the problem more simply. Suppose you have two matrices A and B given as: A = [1 2 3;4 5 6;7 8 9]; and B = [10 20 30;40 50 60;70 80 90] Suppose the entry's of each row are points. I mean (1,1) (2,20) and so on are points. So I have 3 points and will have three figures one per row. How will combine those figures in a Table in mathematica so that you have a movie or animation now. What should be the loop for that $\endgroup$ – Brato Oct 2 '14 at 1:23
  • $\begingroup$ Please have a look at it with matrix A and B $\endgroup$ – Brato Oct 2 '14 at 1:38
  • 4
    $\begingroup$ I am disappointed that this question is not about a screenplay for an upcoming Mathematica feature-length motion picture. $\endgroup$ – Kellen Myers Oct 2 '14 at 1:53
5
$\begingroup$

This should get you started:

xx = {1, 2, 3, 4, 5, 6, 7, 8, 9};
yy = {10, 20, 30, 40, 50, 60, 70, 80, 90};
xy = Transpose[{xx, yy}] // Partition[#, 3] &;

ani = ListPlot[#] & /@ xy;

Then:

ListAnimate[ani]
$\endgroup$
  • $\begingroup$ Really appreciate your help. Your code works fine. But my problem is not resolved. It is because of my stupidity I guess. I created an Array from the Matrix and imported it from Matlab. The problem with that is I have my data like this: {{{1,2,3,4,5}}} instead of {1,2,3,4,5} and that two extra brackets messes things up. Can you suggest anything? Thank you again $\endgroup$ – Brato Oct 2 '14 at 4:18
  • 1
    $\begingroup$ @Brato. First apply Flatten to that list i.e. Flatten[{{{1, 2, 3, 4, 5}}}]. $\endgroup$ – RunnyKine Oct 2 '14 at 4:19
  • $\begingroup$ GREAT!!! Thank you so so much. This works! Really Appreciate Your Help!! $\endgroup$ – Brato Oct 2 '14 at 4:35
  • $\begingroup$ Sorry to bother you again. Can I ask you one more question? Consider the example of the two matrices as I asked above. If I create two plots using the data from them is it possible to animate them in the same figure? I mean I can use Show command to display 2 plots on the same figure. How can I do this for animations? $\endgroup$ – Brato Oct 2 '14 at 6:10
  • $\begingroup$ @Brato. It's best to ask a new question instead of editing an already answered one. It will give it more visibility. For now, I think the answer to the second question is to include both plots into the same Graphics object and Animate that object. $\endgroup$ – RunnyKine Oct 2 '14 at 6:46
3
$\begingroup$

You can generate an animation from time-series data A and B using Animate, and then Export it to any number of desired file formats. For example:

{A, B} = {#, Sin[#]} &@Range[0, 10, 0.1];
Animate[Graphics[{Point[{A[[k]], B[[k]]}]}, Axes -> True, 
  PlotRange -> {{0, 10}, {-1, 1}}], {k, 1, 100, 1}]

which generates the following:

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.