How to use boxchart()?
이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
이전 댓글 표시
1 개 추천
I am trying to use a boxchart for the first time as opposed to a boxplot, as it looks to have better functionality for what I want to do.
But, it's not working and I can't understand what's wrong...
On the x axis I would like to have 22 different dates, represented on the y by a box plot of 22*144 data points.
boxchart(data_dB1,dates_concatenated)
Error using boxchart
Expected ydata to be one of these types:
double, single, uint8, uint16, uint32, uint64, int8, int16, int32, int64
Error in boxchart (line 95)
validateattributes(ydata,{'numeric'},{'2d','real'},mfilename,'ydata');


채택된 답변
Cris LaPierre
2020년 11월 13일
편집: Cris LaPierre
2020년 11월 13일
0 개 추천
I think the error is because you are using the syntax boxchart(xgroupdata,ydata), but your inputs are reversed. You put the grouping variable second. Also, your grouping data is not valid for use as xgroupdata.
boxchart(___,'GroupByColor',cgroupdata)
Therefore, try changing your code to
boxchart(data_dB1,'GroupByColor',dates_concatenated)
댓글 수: 12
Louise Wilson
2020년 11월 16일
Thanks Chris. I am sorry, I see now I was getting it wrong and my question wasn't as clear as it could be. I realise that I do not want to group by date, but by three different categories. I can do this:
h=figure(7);
subplot(5,1,1)
set(h,'WindowStyle','docked')
boxchart(data_dB1);
hold on
boxchart(data_dB2);
boxchart(data_dB3);
ylim([80 150]);
xticklabels(datestr(dates_concatenated1,'dd-mm-yy'));
xtickangle(45);
legend(["50-24,000 Hz","50-5000Hz","50-1500 Hz"]);
title(site,'FontSize',14);
xlabel('Date','FontSize',14); ylabel('SPL_{rms}', 'FontSize',14);
...which will plot a boxchart for each different category on top of each other within one xtick. But, what I want to do for clarity is to have three boxcharts side-by-side within one x-tick, so they can be seen clearly. So, the question is, how do I group these data correctly? Each 'group' is 144*22 double matrix and belongs to one of three categories.
Cris LaPierre
2020년 11월 16일
With hold on, it is doing exactly what it should - placing the plots on top of each other. You will need to include all the data in a single boxchart command.
Louise Wilson
2020년 11월 16일
Yes, I understand it is doing as it should, just that what it should do is not my ideal solution. I have tried to use boxchart as it has legend whereas boxplot does not. I have concatenated all of my data into two arrays:
C=cell(432,22); %labels for each category
C(1:144,1:22)={'50-24,000'};
C(145:288,1:22)={'50:5000'};
C(289:432,1:22)={'50:1500'};
dB_values=[dB1; dB2; dB3]
b=boxchart(dB_values,'GroupByColor',C)
but I get the error:
Error using matlab.graphics.chart.primitive.BoxChart
The name 'GroupByColor' is not an accessible property for
an instance of class
'matlab.graphics.chart.primitive.BoxChart'.
Error in boxchart (line 128)
H = matlab.graphics.chart.primitive.BoxChart('Parent',
cax,...
From the example in the documentation using the patients data, this is what I should do, but it is not working?
Cris LaPierre
2020년 11월 16일
Share your data. Place your variables in a mat file and attach them using the paperclip icon.
Louise Wilson
2020년 11월 16일
Thanks
Cris LaPierre
2020년 11월 16일
What are data_dB1, data_dB2, and data_dB3?
Louise Wilson
2020년 11월 16일
They are here, and concatenated vertically in dB_values. They are dB values.
Cris LaPierre
2020년 11월 17일
편집: Cris LaPierre
2020년 11월 17일
I had to do some investigation myself first. I found this example extremely helpful. Basically, in order to create the plot you want using boxchart, you need to convert your inputs into vectors. All the data needs to be in a single column. To work, you also need to do the following
- create an xgroup vector that indicates which column the corresponding value originally came from.
- create a cgroupdata vector that indicates which data set the corresponding value came from.
I came up with something like this.
% load your data
load data_dB1.mat
load data_dB2.mat
load data_dB3.mat
% Convert each data set into a column vector.
% the (:) basically stacks all columns on top of each other. First #1, the 2 under it, then 3, ...
dB1 = data_dB1(:);
dB2 = data_dB2(:);
dB3 = data_dB3(:);
% Combine all 3 data sets into a single column vector
dB = [dB1;dB2;dB3];
% Create a corresponding x-vector, indicating which column each row came from
x=ones(size(data_dB1,1),1)*(1:size(data_dB1,2));
x = [x(:);x(:);x(:)];
% convert to dates
d=datetime(2019,8,20):days(1):datetime(2019,9,10);
d=categorical(d(x));
% Create a group vector, indicating which data set each row came from
G = ones(size(dB1));
G = [G;G*2;G*3];
% Create boxchart
boxchart(d,dB,'GroupByColor',G)
ylim([80 150]);
legend(["50-24,000 Hz","50-5000Hz","50-1500 Hz"]);
xlabel('Date','FontSize',14); ylabel('SPL_{rms}', 'FontSize',14);

Louise Wilson
2020년 11월 17일
Hi Chris, this is fantastic. Thank you so much for your help, this is exactly what I was looking for. I hadn't seen that example either.
Ioannis Vourvachakis
2021년 12월 16일
Hello. How can I use boxchart? My version of Matlab is 2019a ans sais Undefined function or variable 'boxchart'.
Cris LaPierre
2021년 12월 16일
boxchart was introduced in R2020a. If you have the Statistics and Machine Learning toolbox, you can use boxplot instead. Otherwise, you will need to update your MATLAB version to at least R2020a.
Fuqiang Guo
2021년 12월 23일
Thank you very much, your advice is very helpful, I'll update my software version
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Annotations에 대해 자세히 알아보기
태그
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
