Bar graph plotting problem in GUIDE GUI (previous resolution didn't work; code shown)
3 views (last 30 days)
Show older comments
I posted something like this before but when I examined it carefully, the issue is not resolved.
I am trying to plot the bar graph onto the GUIDE GUI but what seems to happen is that the axes box is empty (graph field empty) in the GUIDE GUI and instead a new figure window opens up that displays the bar graph that I want to display.
How do I go about fixing it so that the bar graph appears in the GUIDE GUI?
I have placed the entire code to run the bar graph into the OpeningFcn of the GUIDE GUI, and there isn't suppose to be any push button or any other kind of trigger to run it. When the GUI appears, it should appear displayed in the GUI.
% Get variables from varDatabase.mat and define them for use here.
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
figure
bar(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 Conjugative 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');
Input would be much appreciated.
0 Comments
Answers (1)
Geoff Hayes
on 16 Dec 2014
Edited: Geoff Hayes
on 16 Dec 2014
Muuaman - in your above code, there is a line that creates a new figure. And so the bar graph will be drawn on that figure and not within your GUI:
% Create a vertical bar chart using the bar function
figure
bar(1:2, [expSingle' expConjugate' ctlSingle' ctlConjugate'], 1)
The current axes becomes that of the new figure, and so all commands to draw or label on the current axes will occur on this figure.
Instead, remove the figure line, and reference your axes explicitly. If axes1 is the name of the axes where you wish your bar chart to appear, then change your call to bar to
bar(handles.axes1, 1:2, [expSingle' expConjugate' ctlSingle' ctlConjugate'], 1);
Do the same for your other commands, replacing gca with handles.axes1 or adding in the latter as necessary.
0 Comments
See Also
Categories
Find more on Bar Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!