Unable to perform assignment because the left side is 1-by-3 and the right side is 1-by-2

1 view (last 30 days)
Hello!
I am still struggling with trying to make graphs with categorical variables and error bars.
I am getting an error in line 11 (starts with ctr) that says "Unable to perform assignment because the left side is 1-by-3 and the right side is 1-by-2".
Am I missing a blatant 1-by-3 vector and how do I fix it without ruining my code? I apprieciate any help I can get, as I started learning Matlab just this year. Thanks!!
Here is my current code:
xc = categorical({'PTSD-','PTSD+'});
x = 1:numel(xc);
y = [.09 .13 ; -.08 -.35];
hBar = bar(x,y);
pos = [.1 .15 .2 .21];
neg = pos
posr = reshape(pos, 2, [2]);
negr = reshape(neg, 2, [2]);
for k1 = 1:size(y,2)
ctr(k1,:) = bsxfun(@plus, 1:numel(hBar(k1).XData), hBar(k1).XOffset');
ydt(k1,:) = hBar(k1).YData;
end
set(gca, 'XTick',x, 'XTickLabel',xc,'FontSize',12, 'FontName', 'Helvetica')
ylabel("Overall Cognitive Functioning (Z-Score)", 'FontSize',12, 'FontName', 'Helvetica')
ylim([-.5 .5]);
yticks([-.5, -.4 -.3 -.2 -.1 0 .1 .2 .3 .4 .5])
legend('location','northeast')
legend('FontName', 'Helvetica', 'FontSize',12)
legend boxoff
box off
legend boxoff
newcolors = ['#CBCBCB'; '#0033A0']
colororder(newcolors)
legend({'Met-','Met+'})
set(gca, 'XTick',x, 'XTickLabel',xc,'FontSize',12, 'FontName', 'Helvetica')

Accepted Answer

Star Strider
Star Strider on 21 Oct 2020
I’m not certain what you’re doing with that line.
The standard way of coding it (to put errorbar objects or text objects at the top of the bars) is:
ctr(k1,:) = bsxfun(@plus, hBar(k1).XData, hBar(k1).XOffset')
I suspect that diference could be the problem, however I find it a bit difficult to follow your code, because I don’t see that you use ‘ctr’ or ‘ydt’ anywhere else.
  4 Comments

Sign in to comment.

More Answers (0)

Categories

Find more on Discrete Data 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!