Farhat Farhat
Farhat Farhat

Reputation: 1

How to show the plotted histogram into axes in matlab GUI?

I wanna plot the histogram and show it into the axes. and the axes is located in an uipanel. How to show the histogram in the axes?

here is my code. and it's just displayed the plotted histogram in a new window.

fontSize = 20;
[pixelCount_Merah grayLevels_Merah] = imhist(Merah);
%subplot(2, 2, 2);
bar(pixelCount_Merah, 'r');
title('Histogram of Merah', 'Fontsize', fontSize);
 xlim([0 grayLevels_Merah(end)]); % Scale x axis manually.

Any suggestions??

Upvotes: 0

Views: 2170

Answers (2)

am304
am304

Reputation: 13876

Use set(figure_handle,'CurrentAxes',axes_handle) before calling the imhist function, where figure_handle is the handle of the figure for your GUI and axes_handle is the handle of the axes in your GUI.

EDIT I went a bit too quickly there. As Hugh Nolan pointed out, you need the axes handles to your axes of interest and then it's just a matter of calling the bar function with the correct axes handle, e.g.:

bar(axes_handle,pixelCount_Merah, 'r');

Upvotes: 0

Hugh Nolan
Hugh Nolan

Reputation: 2519

If you return the axes handle on creation, like so:

%... creating a uipanel somewhere here
h = axes(); % make axes in uipanel

Then you can use

axes(h);

Before you use bar to plot into those axes.

If you don't have the axes handle available, you can use the findall command to find it, so long as you have only created one set of axes:

h=findall(0,'type','axes');

If you have more than one set of axes in your workspace, you could try filtering by finding all of them using the above command, then looking for one whose parent is a uipanel.

Upvotes: 1

Related Questions