(更新 - 新问题) - Matlab - 在 GUIDE GUI 问题中显示条形图



这是我要在 GUIDE GUI 上显示的条形图。我把这段代码放到 GUIDE GUI 的 OpenFcn 函数中,本质上发生的事情是专用于图形的实际框部分(其标记为"axes1"(出现在 GUI 窗口中,但随后出现另一个显示条形图的图形窗口。如何将此条形图放入专用于框轴1的GUIDE GUI中?

我不需要任何按钮触发器来显示它。当 GUI 窗口打开时,图形应出现在 GUIDE GUI 上的专用位置。

编辑:这是我想要显示的图形数据。我以上一个为例,以便我可以从中学习。但是,由于某种原因,下图在窗口中出现两次的问题 - 它出现一次,关闭,然后再次出现。我将如何修复它,使其只出现一次?所有这些都在OpenFcn下,我在CreateFcn下没有其他代码。

dbedit = matfile('varDatabase.mat', 'Writable', true);
results_pData = dbedit.pData;
results_uData = dbedit.uData;
results_name = dbedit.name;
% Create data for each set of bars for data from each group 
% i.e. [participant, population].
% Population is defined as the previous user data stored in its full in uData. 
expSingle = [((results_pData(1,2)/7)*100), ((mean(results_uData(:,2))/7)*100)];
expConjugate = [((results_pData(1,3)/7)*100), ((mean(results_uData(:,3))/7)*100)];
ctlSingle = [((results_pData(1,4)/7)*100), ((mean(results_uData(:,4))/7)*100)];
ctlConjugate = [((results_pData(1,5)/7)*100), ((mean(results_uData(:,5))/7)*100)];
% Create a vertical bar chart using the bar function
bar(handles.axes1,1:2, [expSingle' expConjugate' ctlSingle' ctlConjugate'], 1)
% Set the axis limits
axis([0 2.8 0 100])
set(gca,'XTickLabel',{results_name,'Population'})
% Add title and axis labels
title('Proportion of Responses for Conjunctive vs. Single Choices')
xlabel('Entity')
ylabel('Proportion of Responses (%)')
% Add a legend
legend('Single Choice, Experimental', 'Conjugative Choice, Experimental',...
'Single Choice, Control', 'Conjugative Choice, Control')

如能提供意见,将不胜感激。

这是因为您在创建数据后立即调用图形,这确实会在您的 GUI 之外创建一个新图形。

要解决问题,请删除该行,并考虑在调用bar中添加实际的轴句柄:

bar(handles.axes1,1:12, [measles' mumps' chickenPox'], 1)

因此,您的整个代码可能如下所示:

%Create data for childhood disease cases
measles = [38556 24472 14556 18060 19549 8122 28541 7880 3283 4135 7953 1884];
mumps = [20178 23536 34561 37395 36072 32237 18597 9408 6005 6268 8963 13882];
chickenPox = [37140 32169 37533 39103 33244 23269 16737 5411 3435 6052 12825 23332];
%Create a vertical bar chart using the bar function 
%// Remove the call to figure.
bar(handles.axes1,1:12, [measles' mumps' chickenPox'], 1)
% Set the axis limits
axis([0 13 0 40000])
set(gca, 'XTick', 1:12)
% Add title and axis labels
title('Childhood diseases by month')
xlabel('Month')
ylabel('Cases (in thousands)')
% Add a legend
legend('Measles', 'Mumps', 'Chicken pox')

现在应该可以工作

最新更新