Trying to put a scatterplot onto a boxplot

조회 수: 2 (최근 30일)
Saar Peles
Saar Peles 2020년 10월 26일
편집: dpb 2020년 10월 26일
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
Constantino Carlos Reyes-Aldasoro
Constantino Carlos Reyes-Aldasoro 2020년 10월 26일
Cannot reproduce the error:
Undefined variable "WS" or class "WS.S10.rr_la.Septum".
Vistasp Edulji
Vistasp Edulji 2020년 10월 26일
편집: Vistasp Edulji 2020년 10월 26일
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

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

채택된 답변

dpb
dpb 2020년 10월 26일
편집: dpb 2020년 10월 26일
" 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개)

카테고리

Help CenterFile Exchange에서 Contour Plots에 대해 자세히 알아보기

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by