Error using bar when plotting from variables

1 回表示 (過去 30 日間)
Lukas Netzer
Lukas Netzer 2021 年 5 月 26 日
回答済み: Rik 2021 年 5 月 26 日
I'm trying to plot with the following code:
w1 = 0.5;
x = [1 2 3 4]
y1 = [C1a, C1d, C2a, C2d]
y2 = [C1aO, C1dO, C2aO, C2dO]
bar([x, y1, w1, 'FaceColor',[0.2 0.2 0.5]])
ax = gca;
ax.YLabel.String = "Capacity"
title('Needed Capacity')
w2 = 0.7;
hold on
bar(x,y2 ,w2, 'FaceColor',[0 0.7 0.7])
hold off
Which gets me the stated error. I tried several things like removing ",", etc. but can not figure out where I am going wrong - a hint would be very much appreciated!
Edit:
[C1a, C1d, C2a, C2d] = [1, 2, 3, 4]
[C1aO, C1dO, C2aO, C2dO] = [0, 1, 2, 3]

回答 (1 件)

Rik
Rik 2021 年 5 月 26 日
bar([x, y1, w1, 'FaceColor',[0.2 0.2 0.5]])
% ^ ^
Those brackets are incorrect.

カテゴリ

Help Center および File Exchange2-D and 3-D Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by