필터 지우기
필터 지우기

How can I call a function to draw histogram in GUI?

조회 수: 2 (최근 30일)
MAHMOUD ALZIOUD
MAHMOUD ALZIOUD 2017년 11월 15일
댓글: MAHMOUD ALZIOUD 2017년 11월 16일
Dear all; I have a function written below, this function supposed to provide me with a histogram, when i push the button it must give a histogram in axes1, how can i do that please? knowing that the gui file and the function are in the same folder:
function SingleAxle = ALS_Single( Class9_data )
directory=dir('*.Y07');
for K = 1 : length(directory)
filename = directory(K).name;
fileID = fopen(filename,'r');
formatSpec = '%s';
A_cell = textscan(fileID,formatSpec);
A=char(A_cell{1,1}{:,:});
A(find(isnan(A)))=0;
[rows,columns]=size(A);
if columns~=105
ArrayTemp=zeros(rows,105);
ArrayTemp(1:rows,1:columns)=A;
A=ArrayTemp;
A=char(A);
A(isspace(A)) = '0';
end
Month_of_Data= A(:,14:15);
M=Class9_data;
figure
SingleAxle=100*Class9_data(:,14);
histogram(SingleAxle);
xlabel('Weight in Kg')
ylabel('Counts')
month(K)=unique(str2num(Month_of_Data));
months = month(K);
title(['ALS for C9 Single For Month ',num2str(months)])
end

답변 (1개)

Steven Lord
Steven Lord 2017년 11월 15일
Use this syntax from the documentation for histogram.
"histogram(ax,___) plots into the axes specified by ax instead of into the current axes (gca). The option ax can precede any of the input argument combinations in the previous syntaxes."
Pass the handle of the axes in the GUI as the first input and your data as the second.
  댓글 수: 2
MAHMOUD ALZIOUD
MAHMOUD ALZIOUD 2017년 11월 15일
i was trying to handle and pass like this but it is not working: it keeps saying reference to non existing field. this is my gui fpushbutton function:
% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
SingleAxle=100*Class9_data(:,14);
N= str2double(get(handles.SingleAxle, 'string'));
axes(handles.axes1)
ALS_Single (N);
h = figure();
histogram(h, N)
MAHMOUD ALZIOUD
MAHMOUD ALZIOUD 2017년 11월 16일
I modified it this way but still not working !!
% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
handles.SingleAxle=100*Class9_data(:,14);
N= str2double(get(handles.SingleAxle, 'string'));
axes(handles.axes1)
h = figure();
histogram(ax,h,N)

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Annotations에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by