Need help plotting error bars to my data on a line plot

5 views (last 30 days)
I'm having difficulty plotting error bars along the line plot of my data.
I'm getting the following error:
Error using errorbar>checkSingleInput (line 272)
YNegativeDelta must be empty or the same size as YData.
Error in errorbar (line 135)
yneg = checkSingleInput(neg, sz, 'YNegativeDelta');
Error in Experiment1_ParticipantLearningRate_Figure2 (line 41)
errorbar(y, eb_interval, allsubs_cond0_stderr)
Below is the script I'm using. For added context, allsubs_response_cond0_trials and allsubs_response_cond1_trials are both 120 x 40 matrices that represent the probability correct from 120 trials of 40 participants.
%%%Participant Learning Rate Figure%%%
%Creates Figure and plots data
figure; plot((smooth(mean(allsubs_response_cond0_trials, 2))),'LineWidth',2);
hold on
plot((smooth(mean(allsubs_response_cond1_trials, 2))),'LineWidth',2);
%Creates title
title('Participant Learning Curve')
%Creates legend in bottom-left corner
legend({'Concrete First','Abstract First'},'Location','southeast')
% Create ylabel
ylabel('Probability of Correct Response','FontSize',24,...
'FontName','Times New Roman');
% Create xlabel
xlabel({'Trial Number'},'FontSize',24,'FontName','Times New Roman');
% Defines participant learning rate standard error for each condition
allsubs_cond0_stderr = std(allsubs_p_correct_hist_cond0)./sqrt(length(allsubs_p_correct_hist_cond0));
allsubs_cond1_stderr = std(allsubs_p_correct_hist_cond1)./sqrt(length(allsubs_p_correct_hist_cond1));
%Transposes learning curve dimensions to compute error bars(changes 120x40
%to 40x120)
allsubs_response_cond0_trials = allsubs_response_cond0_trials';
allsubs_response_cond1_trials = allsubs_response_cond1_trials';
% Creates errorbars interval at every 10 trials along the x-axis from 10 to
% 120
eb_interval = 10:10:120;
% Creates point on y-axis along data to plot error bars. My intention here
% is to take the mean probability of correct of all 40 participants at each
% desired interval point.
y = mean((allsubs_response_cond0_trials(:,eb_interval)));
% Plots error bars
errorbar(y, eb_interval, allsubs_cond0_stderr)
%Formats current axis and current figure
set(gca, 'FontSize', 18, 'FontWeight', 'bold')
set(gcf, 'Color', 'w')
Ryan Gallagher
Ryan Gallagher on 15 Aug 2021
This is a screen shot of the .mat file that is loaded in the beginning of the script. For clarification, "allsubs_response_cond0_trials" is the probability of correct for 120 trials and all 40 participants. The other variable you reference "allsubs_cond0_stderr" is the singular value representing the standard error calculated for each condition.

Sign in to comment.

Accepted Answer

Shanmukha Voggu
Shanmukha Voggu on 3 Sep 2021
Hi Ryan,
The error is due to the third argument of the errorbar function is not of the same size as the first argument.
The third argument allsubs_cond0_stderr is a constant and the first argument y is [1 x 12] matrix.
A possible fix that will resolve the error is to make the allsubs_cond0_stderr as [1 x 12] matrix (changing constant to matrix that has each and every value equal to constant)
% Plots error bars
allsubs_cond0_stderr=allsubs_cond0_stderr(ones(size(y)));% add this line above the errorbar function
errorbar(y, eb_interval, allsubs_cond0_stderr);
Refer to this for more information.

More Answers (0)




Community Treasure Hunt

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

Start Hunting!