how to plot group box-lot with use of function multiple box-lot

hi,
I have to make group boxplot into group 1 and 2. I am using function mutiple boxplot , but error is showing me undefined function of multiple_boxplot. I dont where i am going wrong, is this because of the matlab version. Please if somebody can help me in resolving this problem.
Thanks
x1=e.X1;
x2=e.X2;
X=[x1,x2];
y1=e.Y1;
y2=e.Y2;
Y=[y1,y2];
data = [X,Y]
data=cell(2,2);
for ii=1:size(data,1)
Xc{ii}=X(:,ii);
Yc{ii}=Y(:,ii);
end
data=vertcat(Xc,Yc);
xlab={'TSS','TP'};
multiple_boxplot(data',xlab,{'Malvern','Carling street'});
color = ['c', 'y', 'c', 'y'];
h = findobj(gca,'Tag','Box');
for j=1:length(h)
patch(get(h(j),'XData'),get(h(j),'YData'),color(j),'FaceAlpha',.5);
end
c = get(gca, 'Children');
hleg1 = legend(c(1:2);
data =
47.2925 17.8000 2.5930 0.4560
98.9950 41.0000 6.5235 1.8600
247.6635 8.3940 10.2760 4.9480
Unrecognized function or variable 'multiple_boxplot'.

 Accepted Answer

multiple_boxplot is not built in to MATLAB. It looks like it is a user-contributed functoin that you can download from the File Exchange here.

7 Comments

Thank you, I have download. but there is some problem with the code. I need group of 2 in 3 different catorgies.
I am using this code but it is giving wrong xlabel.i dont understand what is the problem. Please can you help.
x1=e.X1;
x2=e.X2;
X=[x1,x2];
y1=e.Y1;
y2=e.Y2;
Y=[y1,y2];
z1=e.Z1;
z2=e.Z2;
Z=[z1,z2];
data = [X,Y,Z]
data=cell(3,2);
for ii=1:size(data,1)
Xc{ii}=X(:,ii);
Yc{ii}=Y(:,ii);
Zc{ii}=Z(:,ii);
end
data=vertcat(Xc,Yc,Zc);
xlab={'TSS','TP','TN'};
multiple_boxplot(data',xlab,{'Surrey Down', 'Lake hills'});
Can you upload the data? You can use the paper clip icon in the INSERT section of the toolbar.
Also, can you be more specific what you mean by "it is giving wrong xlabel"?
I've never used that function, so not sure I can help. With a function that is so old (and not maintained), it can be difficult to know if there is a possible error in the function, or if you are making a mistake in how it is called.
Thankyou so much for your help. when i am running my code, the error is Index in position 2 exceeds array bounds (must not exceed 2).
I have attached the data.
thanks
Are you getting that error on this line?
Xc{ii}=X(:,ii);
That has nothing to do with the plotting function.
I wonder if maybe your for loop should be
for ii=1:size(data,2) % instead of size(data,1)
If you make that change, then you at least get to the plotting function. But then THAT gives an error about having the wrong number of labels (which I did not try to debug).
I have loop but i have not got any boxplot , it is giving me an error og wrong number of label. I have used this function for 2 groups in 2 catorgories , that time i was getting the boxplot. is there any other way ,we could help me plot this boxplot.
Thanks
I see now that your code tries to mimic the syntax in the example on the FEX. That example works, but it is terrible code for a few reasons. I think I have made a better example below, but tried to keep close to the example, so it is not too confusing for you. (The code could be much cleaner if rewritten from scratch.)
% Pulling data from your online file. You can use your local file.
e = readtable("https://www.mathworks.com/matlabcentral/answers/uploaded_files/1163403/data.xlsx");
x1=e.X1;
x2=e.X2;
X=[x1,x2];
y1=e.Y1;
y2=e.Y2;
Y=[y1,y2];
z1=e.Z1;
z2=e.Z2;
Z=[z1,z2];
data=cell(2,3); % This variable is weirdly used only to get the dimension, and then overwritten later??? Would have been better to get from X directly.
for ii=1:size(data,1)
Xc{ii}=X(:,ii);
Yc{ii}=Y(:,ii);
Zc{ii}=Z(:,ii);
end
data=vertcat(Xc,Yc,Zc);
xtickLabels={'Data column 1','Data column 2'};
legendLabel = {'X','Y','Z'};
figure
multiple_boxplot(data',xtickLabels,{'X','Y','Z'});
Thank you so much . It been a great help.

Sign in to comment.

More Answers (0)

Tags

Community Treasure Hunt

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

Start Hunting!