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

1 次查看(过去 30 天)
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')

采纳的回答

Star Strider
Star Strider 2020-10-21
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 个评论

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Discrete Data Plots 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by