Error when trying to plot multiple box plot's in the same graph.
Mostrar comentarios más antiguos
I'm trying to make a graph that will have 6 different box and whisker plots in it, with the X axis showing the brain area and the Y axis being the time of the first seizure (I'm doing electrophysiology). I want it to look similar to "Create Box Plots for Grouped Data" found here https://uk.mathworks.com/help/stats/boxplot.html#d120e117421. However, when it reaches the boxplot function it gives me the error ""G must be the same length as X or the same length as the number of columns in X." However, I stepped through my script and checked the variables and the X and G are the exact same length (6X13 double), so I'm not sure why it's giving me this error? My script is bellow:
File = input('What file do you want analyze?\n');
variableName = input('What is the name of the variable?\n');
varName = eval(variableName);
cnt = length(varName);
kcnt1Table = zeros(6,cnt);
for i = 1:cnt
colNoClose = input('Which NC is closest?\n');
colNoFar = input('Which NC is farthest?\n');
if ~isempty(varName{1,i}.Savedresults{1,colNoClose}.output.SeizureTimes(:,1))
time1 = varName{1,i}.Savedresults{1,colNoClose}.output.SeizureTimes(1,1);
else
time1 = 0;
end
if ~isempty(varName{1,i}.Savedresults{1,colNoFar}.output.SeizureTimes(:,1))
time2 = varName{1,i}.Savedresults{1,colNoFar}.output.SeizureTimes(1,1);
else
time2 = 0;
end
if ~isempty(varName{1,i}.Savedresults{1,3}.output.SeizureTimes(:,1))
time3 = varName{1,i}.Savedresults{1,3}.output.SeizureTimes(1,1);
else
time3 = 0;
end
if ~isempty(varName{1,i}.Savedresults{1,4}.output.SeizureTimes(:,1))
time4 = varName{1,i}.Savedresults{1,4}.output.SeizureTimes(1,1);
else
time4 = 0;
end
if ~isempty(varName{1,i}.Savedresults{1,5}.output.SeizureTimes(:,1))
time5 = varName{1,i}.Savedresults{1,5}.output.SeizureTimes(1,1);
else
time5 = 0;
end
if ~isempty(varName{1,i}.Savedresults{1,6}.output.SeizureTimes(:,1))
time6 = varName{1,i}.Savedresults{1,6}.output.SeizureTimes(1,1);
else
time6 = 0;
end
kcnt1Table (:,i) = [time1;time2;time3;time4;time5;time6];
end
%% Plotting
ncClose = kcnt1Table(1,:);
ncFar = kcnt1Table(2,:);
pSub = kcnt1Table(3,:);
Sub = kcnt1Table(4,:);
lEC = kcnt1Table(5,:);
mEC = kcnt1Table(6,:);
group = [ ones(size(ncClose));
2* ones(size(ncFar));
3* ones(size(pSub));
4* ones(size(Sub));
5* ones(size(lEC));
6* ones(size(mEC))];
figure(1)
boxplot(kcnt1Table,group)
set(gca,'XTickLabel',{'NC(close)','NC(Far)','pSub','Sub','lEC','mEC'})
title ('Time to First Seizure')
xlabel('Brain Area')
ylabel('Time of First Seizure (s) ')
By the way, I know that eval should be used sparingly and should be avoided, however it was the only function that I could get to work.
4 comentarios
the cyclist
el 21 de Jun. de 2020
We can't reproduce the error with the information you have provided.
I would recommend the following:
Type
dbstop if error
in the command line before you run your code. Then run as normal. The code will stop when the error occurs. You can then examine the workspace to see exactly what it looks like. Presumably, you'll see exactly what is causing the error in boxplot.
Type
dbclear if error
to removing the automatic breakpoint on error, when you are done debugging.
Mark Gauthier-Braham
el 21 de Jun. de 2020
the cyclist
el 21 de Jun. de 2020
Editada: the cyclist
el 21 de Jun. de 2020
Strange. Can you save the workspace as it is at the moment to a MAT file, and upload it here? Use the paper clip icon in the INSERT section of the toolbar that appears in the editing window here.
Mark Gauthier-Braham
el 21 de Jun. de 2020
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Box Plots en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!