I have data which I have attached to the question (T_Stand_For_Sum). I want to display the first column as x-axis points, with the second column values as the bar heights. I have tried the following and recieved the following errors
xbar = T_Stand_For_Sum.ADBStand;
ybar = T_Stand_For_Sum.KWH;
bar(xbar,ybar);
Error using bar (line 41)
Not enough input arguments.
Error in Model_V_04 (line 234)
bar(xbar,ybar);
xbar = categorical({'T_Stand_For_Sum.ADBStand'});
ybar = T_Stand_For_Sum.KWH;
bar(xbar,ybar);
Error using bar (line 213)
Data inputs must match the axis configuration. A numeric axis must have numeric data inputs or data
inputs which can be converted to double.
Error in Model_V_04 (line 232)
bar(xbar,ybar);
bar(categorical(T_Stand_For_Sum{1:k, 1}), T_Stand_For_Sum{1:k, 2});
Error using bar (line 213)
Data inputs must match the axis configuration. A numeric axis must have numeric data inputs or data
inputs which can be converted to double.
Error in Model_V_04 (line 223)
bar(categorical(T_Stand_For_Sum{1:k, 1}), T_Stand_For_Sum{1:k, 2});

 채택된 답변

Simon Chan
Simon Chan 2021년 8월 4일

0 개 추천

Try this:
bar(categorical(T_Stand_For_Sum.ADBStand),T_Stand_For_Sum.KWH)

댓글 수: 4

Mark Maders
Mark Maders 2021년 8월 4일
I still recieve an error with this line of code
Error using bar (line 213)
Data inputs must match the axis configuration. A numeric axis must have numeric data inputs or data
inputs which can be converted to double.
Error in Model_V_04 (line 238)
bar(categorical(T_Stand_For_Sum.ADBStand),T_Stand_For_Sum.KWH)
Mark Maders
Mark Maders 2021년 8월 4일
T_Stand_For_Sum is a table. Is this why the error is appearing? I have tried converting it to other formats but cannot manage that either
Forgot to mention one step:
(1) You may close figure 1 and then run the script, or
(2) Put figure 2 as follows, you will get two figures
load('T_Stand_For_Sum.mat');
figure(2);
bar(categorical(T_Stand_For_Sum.ADBStand),T_Stand_For_Sum.KWH)
Mark Maders
Mark Maders 2021년 8월 4일
thank you that is working now

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Peter Perkins
Peter Perkins 2021년 8월 5일

1 개 추천

Simon's solution is one way to do it. But using categorical just to label the bars is kind of an abuse of categorical, which is intended to represent data where you have a large number of elements drawn from a small number of discrete values. Lots of repeated values.
Another way to label the bars is to just label them:
>> bar(T_Stand_For_Sum.KWH)
>> set(gca,"XTick",1:33,"XTickLabel",T_Stand_For_Sum.ADBStand)

카테고리

도움말 센터File Exchange에서 Annotations에 대해 자세히 알아보기

제품

릴리스

R2021a

태그

질문:

2021년 8월 4일

답변:

2021년 8월 5일

Community Treasure Hunt

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

Start Hunting!

Translated by