Plotting histogram in Matlab Gui

I try to plot a histogram in Matlab Gui using axis control. But nothing change after running code below:
Code:
handles.hist=hist(sort(averSpectrum),500);
guidata(hObject, handles);
What is wrong I have tried almost every combination.

 採用された回答

Image Analyst
Image Analyst 2013 年 8 月 19 日

0 投票

[counts, binCenters] = hist(sort(averSpectrum),500);
axes(handles.whateverAxesYouWant);
bar(binCenters, counts, 'BarWidth', 1);
grid on;

3 件のコメント

Jonasz
Jonasz 2013 年 8 月 19 日
I have still problem with some error :
??? Error using ==> axes
*Invalid object handle*
Error in ==> program>resamp_Callback at 92
axes(handles.hist);
Error in ==> gui_mainfcn at 96
feval(varargin{:});
Error in ==> program at 42
gui_mainfcn(gui_State, varargin{:});
Error in ==>
@(hObject,eventdata)program('resamp_Callback',hObject,eventdata,guidata(hObject))
??? Error while evaluating uicontrol Callback
My whole code in this callback :
function resamp_Callback(hObject, eventdata, handles)
% hObject handle to resamp (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
[minR,maxR,list,count,averSpectrum,averIntensity,setX,df]=resampling(10);
handles.averSpec=plot(setX,averSpectrum);
set(handles.vmin,'String',num2str(min(setX)));
set(handles.vmax,'String',num2str(max(setX)));
set(handles.myList, 'String', cellstr(num2str(setX(:))));
counts, binCenters] = hist(sort(averSpectrum),500);
axes(handles.hist);
bar(binCenters, counts, 'BarWidth', 1);
grid on;
guidata(hObject, handles);
Image Analyst
Image Analyst 2013 年 8 月 19 日
Double click the axes where you want to display the histogram to bring up the property inspector. Then look at the "tag" property. What does it say? Is the value of the tag property "hist" or is it some other word?
Jonasz
Jonasz 2013 年 8 月 19 日
I find what happen. It's the same name of variable and tag. Sorry for bothering you but it wasn't so obvious for me

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by