Trying to put a scatterplot onto a boxplot
2 views (last 30 days)
Show older comments
Hi I'm trying to put a scatterplot on a boxplot. Currently my boxplot plots fine but the scatterplot is giving me issues and I'm not sure why. Both the X and Y variables I input into it are 16x4, the X is a double and the Y is a categorical. This is the code and the error I keep getting.
AHA2 = repmat({'2'}, 4, 1);
AHA3 = repmat({'3'}, 4, 1);
AHA8 = repmat({'8'}, 4, 1);
AHA9 = repmat({'9'}, 4, 1);
AHA14 = repmat({'14'}, 4, 1);
%setup for Wall AHA regions
AHA1 = repmat({'1'}, 4, 1);
AHA4 = repmat({'4'}, 4, 1);
AHA5 = repmat({'5'}, 4, 1);
AHA6 = repmat({'6'}, 4, 1);
AHA7 = repmat({'7'}, 4, 1);
AHA10 = repmat({'10'}, 4, 1);
AHA11 = repmat({'11'}, 4, 1);
AHA12 = repmat({'12'}, 4, 1);
AHA13 = repmat({'13'}, 4, 1);
AHA15 = repmat({'15'}, 4, 1);
AHA16 = repmat({'16'}, 4, 1);
g_test = categorical([AHA2, AHA3, AHA8, AHA9, AHA14, AHA1, AHA4, AHA5, AHA6, AHA7, AHA10, AHA11, AHA12, AHA13, AHA15, AHA16])';
boXP.rr_la.Septum = [WS.S10.rr_la.Septum; WS.S11.rr_la.Septum; WS.S12.rr_la.Septum; WS.S13.rr_la.Septum]';
boXP.rr_la.Wall = [WS.S10.rr_la.Wall; WS.S11.rr_la.Wall; WS.S12.rr_la.Wall; WS.S13.rr_la.Wall]';
boXP.rr_la.WS_ready = [boXP.rr_la.Septum;boXP.rr_la.Wall];
boxplot(boXP.rr_la.WS_ready,g);
hold on;
scatter(g_test,boXP.rr_la.WS_ready);
hold off;
>> Boxplot_Numerical
Error using scatter (line 78)
X and Y must be vectors of the same length.
Error in Boxplot_Numerical (line 165)
scatter(g_test,boXP.rr_la.WS_ready);
I rechecked about 10 times and boXP.rr_la.WS_ready is a 16x4 double. Not sure whats going on, any help is appreciated
2 Comments
Constantino Carlos Reyes-Aldasoro
on 26 Oct 2020
Cannot reproduce the error:
Undefined variable "WS" or class "WS.S10.rr_la.Septum".
Vistasp Edulji
on 26 Oct 2020
Edited: Vistasp Edulji
on 26 Oct 2020
boXP.rr_la.Septum = [WS.S10.rr_la.Septum; WS.S11.rr_la.Septum; WS.S12.rr_la.Septum; WS.S13.rr_la.Septum]';
boXP.rr_la.Wall = [WS.S10.rr_la.Wall; WS.S11.rr_la.Wall; WS.S12.rr_la.Wall; WS.S13.rr_la.Wall]';
The above two lines create a column vector of1x4(the files inside the bracket are missing so I can only assume) which is then transpossed to 4x1 row vector.
boXP.WS_ready = [boXP.rr_la.Septum;boXP.rr_la.Wall];
This line then takes both Row vectors and converts it to 2x4 array. Again I dont have the files inside the [] so can't comment but most likely it is an issue of how the vectors are appended to each other
Accepted Answer
dpb
on 26 Oct 2020
Edited: dpb
on 26 Oct 2020
" Both the X and Y variables I input into it are 16x4, ..."
As the error message clearly says,
Error using scatter (line 78)
X and Y must be vectors of the same length.
scatter() documentation states for inputs x,y --
x — x values
vector
x values, specified as a vector. x and y must be vectors of equal length.
To use scatter() you must arrange the input data as vectors, not 2D arrays.
0 Comments
More Answers (0)
See Also
Categories
Find more on Contour Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!