Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Different frame title/axes in a movie

Subject: Different frame title/axes in a movie

From: David

Date: 24 Feb, 2012 12:28:13

Message: 1 of 5

Hi,

I have a movie of 38 frames.
Each frame is a filled contour plot corresponding to a different year (from 1973-2011).
I need each frame to have the title of which year it is; so each frame will have a different title. Is there any way of doing this?
If it is not possible to do this with the title then can the axes change each frame?

Thanks for any help.
Dave

Subject: Different frame title/axes in a movie

From: William Frane

Date: 24 Feb, 2012 15:58:11

Message: 2 of 5

Hello Dave,

Are you generating the movie with MATLAB, or is it a pre-existing file? ("I have a movie" is a bit vague.) Assuming the former, if you're generating the movie by iterating through the years 1973 to 2011, creating a contour plot of the data for a given year on a single axis, and then calling addframe in each iteration to add the current year's plot to your movie, I would recommend simply using the title function to change the axis (and thus frame) title in each iteration.

Roughly, this would look something like:

for year = 1973:2011

% Create new or adjust existing figure as necessary for video (e.g., set size to 1280 by 720 pixels or whatever your frame size of choice is)

% Plot the data for the current year

% Set the title for the current frame
title(['Year: ' num2str(year)]);

% Add the current plot to the movie
aviObj = addframe(aviObj, getframe(gcf));

end

Hope that helps.

W Frane

"David " <sum_is_41@hotmail.com> wrote in message <ji7vos$898$1@newscl01ah.mathworks.com>...
> Hi,
>
> I have a movie of 38 frames.
> Each frame is a filled contour plot corresponding to a different year (from 1973-2011).
> I need each frame to have the title of which year it is; so each frame will have a different title. Is there any way of doing this?
> If it is not possible to do this with the title then can the axes change each frame?
>
> Thanks for any help.
> Dave

Subject: Different frame title/axes in a movie

From: David

Date: 24 Feb, 2012 16:13:22

Message: 3 of 5

Sorry yes it is a movie generated in MATLAB. In order to do what you are suggesting does my movie have to be converted into avi format?

Dave

"William Frane" wrote in message <ji8c2j$koo$1@newscl01ah.mathworks.com>...
> Hello Dave,
>
> Are you generating the movie with MATLAB, or is it a pre-existing file? ("I have a movie" is a bit vague.) Assuming the former, if you're generating the movie by iterating through the years 1973 to 2011, creating a contour plot of the data for a given year on a single axis, and then calling addframe in each iteration to add the current year's plot to your movie, I would recommend simply using the title function to change the axis (and thus frame) title in each iteration.
>
> Roughly, this would look something like:
>
> for year = 1973:2011
>
> % Create new or adjust existing figure as necessary for video (e.g., set size to 1280 by 720 pixels or whatever your frame size of choice is)
>
> % Plot the data for the current year
>
> % Set the title for the current frame
> title(['Year: ' num2str(year)]);
>
> % Add the current plot to the movie
> aviObj = addframe(aviObj, getframe(gcf));
>
> end
>
> Hope that helps.
>
> W Frane
>
> "David " <sum_is_41@hotmail.com> wrote in message <ji7vos$898$1@newscl01ah.mathworks.com>...
> > Hi,
> >
> > I have a movie of 38 frames.
> > Each frame is a filled contour plot corresponding to a different year (from 1973-2011).
> > I need each frame to have the title of which year it is; so each frame will have a different title. Is there any way of doing this?
> > If it is not possible to do this with the title then can the axes change each frame?
> >
> > Thanks for any help.
> > Dave

Subject: Different frame title/axes in a movie

From: David

Date: 24 Feb, 2012 16:39:25

Message: 4 of 5

I have tried what you suggested but it just seems to show the one frame whilst going from 1973 to 2011 at the title...
The code i tried is as follows:

for year=1973:2011;
    contourf(annmean(:,:,1));
    title(['Year:' num2str(year)]);
    aviobj=addframe(aviobj, getframe(gcf));
end

I'm sure it is just me doing something wrong as I am new to this movie business on MATLAB, but could you maybe point me in the right direction if it is?

Thank you



"William Frane" wrote in message <ji8c2j$koo$1@newscl01ah.mathworks.com>...
> Hello Dave,
>
> Are you generating the movie with MATLAB, or is it a pre-existing file? ("I have a movie" is a bit vague.) Assuming the former, if you're generating the movie by iterating through the years 1973 to 2011, creating a contour plot of the data for a given year on a single axis, and then calling addframe in each iteration to add the current year's plot to your movie, I would recommend simply using the title function to change the axis (and thus frame) title in each iteration.
>
> Roughly, this would look something like:
>
> for year = 1973:2011
>
> % Create new or adjust existing figure as necessary for video (e.g., set size to 1280 by 720 pixels or whatever your frame size of choice is)
>
> % Plot the data for the current year
>
> % Set the title for the current frame
> title(['Year: ' num2str(year)]);
>
> % Add the current plot to the movie
> aviObj = addframe(aviObj, getframe(gcf));
>
> end
>
> Hope that helps.
>
> W Frane
>
> "David " <sum_is_41@hotmail.com> wrote in message <ji7vos$898$1@newscl01ah.mathworks.com>...
> > Hi,
> >
> > I have a movie of 38 frames.
> > Each frame is a filled contour plot corresponding to a different year (from 1973-2011).
> > I need each frame to have the title of which year it is; so each frame will have a different title. Is there any way of doing this?
> > If it is not possible to do this with the title then can the axes change each frame?
> >
> > Thanks for any help.
> > Dave

Subject: Different frame title/axes in a movie

From: William Frane

Date: 24 Feb, 2012 19:24:13

Message: 5 of 5

Unless it's a just a typo in your post, I think you'd want
contourf(annmean(:,:,year-1972));
(assuming annmean starts at 1) instead of
contourf(annmean(:,:,1));

If you want to export an AVI video, you'll need to initialize an AVI object using the avifile command. However, I noticed your other post, which states that you were originally using getframe and then the movie command.

With no arguments, getframe only captures the area inside the current axis, which would omit the axis title. To capture the entire figure (which should include the axis title), you can use the syntax getframe(gcf) (of course, you don't have to use gcf; any appropriate figure handle will work). For the record, this is documented under the heading "Capture Regions" in the help file for getframe.

W Frane

"David " <sum_is_41@hotmail.com> wrote in message <ji8eft$1s$1@newscl01ah.mathworks.com>...
> I have tried what you suggested but it just seems to show the one frame whilst going from 1973 to 2011 at the title...
> The code i tried is as follows:
>
> for year=1973:2011;
> contourf(annmean(:,:,1));
> title(['Year:' num2str(year)]);
> aviobj=addframe(aviobj, getframe(gcf));
> end
>
> I'm sure it is just me doing something wrong as I am new to this movie business on MATLAB, but could you maybe point me in the right direction if it is?
>
> Thank you
>
>
>
> "William Frane" wrote in message <ji8c2j$koo$1@newscl01ah.mathworks.com>...
> > Hello Dave,
> >
> > Are you generating the movie with MATLAB, or is it a pre-existing file? ("I have a movie" is a bit vague.) Assuming the former, if you're generating the movie by iterating through the years 1973 to 2011, creating a contour plot of the data for a given year on a single axis, and then calling addframe in each iteration to add the current year's plot to your movie, I would recommend simply using the title function to change the axis (and thus frame) title in each iteration.
> >
> > Roughly, this would look something like:
> >
> > for year = 1973:2011
> >
> > % Create new or adjust existing figure as necessary for video (e.g., set size to 1280 by 720 pixels or whatever your frame size of choice is)
> >
> > % Plot the data for the current year
> >
> > % Set the title for the current frame
> > title(['Year: ' num2str(year)]);
> >
> > % Add the current plot to the movie
> > aviObj = addframe(aviObj, getframe(gcf));
> >
> > end
> >
> > Hope that helps.
> >
> > W Frane
> >
> > "David " <sum_is_41@hotmail.com> wrote in message <ji7vos$898$1@newscl01ah.mathworks.com>...
> > > Hi,
> > >
> > > I have a movie of 38 frames.
> > > Each frame is a filled contour plot corresponding to a different year (from 1973-2011).
> > > I need each frame to have the title of which year it is; so each frame will have a different title. Is there any way of doing this?
> > > If it is not possible to do this with the title then can the axes change each frame?
> > >
> > > Thanks for any help.
> > > Dave

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us