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:
Colorbar changes each frame in a movie

Subject: Colorbar changes each frame in a movie

From: David

Date: 28 Feb, 2012 16:23:13

Message: 1 of 3

Hi,

I have made a MATLAB movie with 38 frames; each frame needs a colour bar but the colour bar needs to be exactly the same in each frame. At the moment each frame has a colour bar with different values rendering the movie useless.

The coding used to make the movie is below for reference.

Any help is much appreciated

for i=1973:2010;
    contourf(annmean(:,:,i-1972));
    title(['Year:' num2str(i)]);
    colorbar;
    M(i-1972)=getframe(gcf);
end

Subject: Colorbar changes each frame in a movie

From: Mathew Thomas

Date: 28 Feb, 2012 18:28:14

Message: 2 of 3

I think the values for each frame need to be scaled before display. I think the intensity value for each pixel in each of your frames are different, hence the variations in the colormap. Scale all the values between 0 and 100 or so.

Something like this:
                    new_min = 0;
                    new_max = 100;
                    old_min = min(frame(:));
                    old_max = max(frame(:));
                    for i = 1:size(frame,1)
                        value = sum_of_intensities(:, frame);
                        xnorm(i,frame) = ((value - old_min)./(old_max - old_min)).*(new_max - new_min) + (new_min);
                    end

So all the values will be between 0 and 100.

Subject: Colorbar changes each frame in a movie

From: Kelly Kearney

Date: 28 Feb, 2012 19:15:14

Message: 3 of 3

"David " <sum_is_41@hotmail.com> wrote in message <jiiv1h$e4g$1@newscl01ah.mathworks.com>...
> Hi,
>
> I have made a MATLAB movie with 38 frames; each frame needs a colour bar but the colour bar needs to be exactly the same in each frame. At the moment each frame has a colour bar with different values rendering the movie useless.
>
> The coding used to make the movie is below for reference.
>
> Any help is much appreciated
>
> for i=1973:2010;
> contourf(annmean(:,:,i-1972));
> title(['Year:' num2str(i)]);
> colorbar;
> M(i-1972)=getframe(gcf);
> end

You need to set the color limits of the axis:

set(gca, 'clim', [minval maxval]);

where minval and maxval are the minimum and maximum values seen in annmean(:,:1973:2010). Insert this line prior to the getframe command, and then all your axes (and their colorbars) will have the same color limits.

-Kelly

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