Clear Filters
Clear Filters

How to plot .mat files in boxplot?

3 views (last 30 days)
Halee Scott
Halee Scott on 8 Apr 2022
Commented: Voss on 14 Apr 2022
Hello, I am trying to plot these three data files of mean fluorescence intensity from microscopy analyses and can't figure out how to plot three different data sets. I have only ever plotted control v. treatment. (I am still new to coding and don't have a strong background in computer science) This is my current code and error:
load Ter119WT.mat intensity
WT = intensity;
load Ter119P95H.mat intensity
P95H = intensity;
load Ter119P95Hrip.mat intensity
P95Hrip = intensity;
DATA = [WT;P95H;P95Hrip];
GROUP = [ones(size(WT));2*ones(size(P95H));3*ones(size(P95Hrip))];
figure
set(gcf,'color','w','units','inches','position',[1 1 4 4])
boxplot(DATA,GROUP)
set(gca,'ylim',[3000 9000], 'xticklabel',{'WT','P95H','P95HD'},'fontweight','bold','fontsize',11,...
'linewidth',1.5,'xcolor','k','ycolor','k');
set(findobj(gca,'Tag','Box'),'LineWidth',1.5);
lines = findobj(gcf, 'type', 'line', 'Tag', 'Median');
set(lines,'LineWidth',1.5);
set(findobj(gca,'Tag','Lower Whisker'),'Linewidth',1.5);
set(findobj(gca,'Tag','Upper Whisker'),'Linewidth',1.5);
set(findobj(gca,'Tag','Upper Adjacent Value'),'Linewidth',1.5);
set(findobj(gca,'Tag','Lower Adjacent Value'),'Linewidth',1.5);

Answers (1)

Voss
Voss on 8 Apr 2022
You mention an error, but I'm not sure if you mean you got an error message or just that the plot is not what you expected. If you got an error message, post it and someone can figure out what's wrong. (It may also be useful if you upload your mat files, if that's feasible.)
In any case, here's how you can avoid using findobj, and instead set the lines' properties more directly (this uses random data where each data set is one column):
% load Ter119WT.mat intensity
% WT = intensity;
% load Ter119P95H.mat intensity
% P95H = intensity;
% load Ter119P95Hrip.mat intensity
% P95Hrip = intensity;
WT = 3000+6000*rand(100,1);
P95H = 3000+6000*rand(90,1);
P95Hrip = 3000+6000*rand(110,1);
DATA = [WT;P95H;P95Hrip];
GROUP = [ones(size(WT));2*ones(size(P95H));3*ones(size(P95Hrip))];
figure
set(gcf,'color','w','units','inches','position',[1 1 4 4])
h = boxplot(DATA,GROUP) % use the line handles returned from boxplot, here I call them "h"
h = 7×3
10.0038 17.0035 24.0035 11.0035 18.0035 25.0035 12.0035 19.0035 26.0035 13.0035 20.0035 27.0035 14.0035 21.0035 28.0035 15.0035 22.0035 29.0035 16.0035 23.0035 30.0035
reshape(get(h,'Tag'),size(h)) % check out the Tags to know what's what
ans = 7×3 cell array
{'Upper Whisker' } {'Upper Whisker' } {'Upper Whisker' } {'Lower Whisker' } {'Lower Whisker' } {'Lower Whisker' } {'Upper Adjacent Value'} {'Upper Adjacent Value'} {'Upper Adjacent Value'} {'Lower Adjacent Value'} {'Lower Adjacent Value'} {'Lower Adjacent Value'} {'Box' } {'Box' } {'Box' } {'Median' } {'Median' } {'Median' } {'Outliers' } {'Outliers' } {'Outliers' }
set(gca,'ylim',[3000 9000], 'xticklabel',{'WT','P95H','P95HD'},'fontweight','bold','fontsize',11,...
'linewidth',1.5,'xcolor','k','ycolor','k');
% set(findobj(gca,'Tag','Box'),'LineWidth',1.5);
% lines = findobj(gcf, 'type', 'line', 'Tag', 'Median');
% set(lines,'LineWidth',1.5);
% set(findobj(gca,'Tag','Lower Whisker'),'Linewidth',1.5);
% set(findobj(gca,'Tag','Upper Whisker'),'Linewidth',1.5);
% set(findobj(gca,'Tag','Upper Adjacent Value'),'Linewidth',1.5);
% set(findobj(gca,'Tag','Lower Adjacent Value'),'Linewidth',1.5);
set(h(1:6,:),'LineWidth',1.5);
  4 Comments
Halee Scott
Halee Scott on 14 Apr 2022
Additionally I think that the way I am loading my files is not correct because it is not accessing the stored variables properly.
ERROR message: Error in boxplot (line 274)
[xDat,gDat,origRow,xlen,gexplicit,origInd,origNumXCols] = straightenX(x,g);
Error in General_IA_Script_boxplot (line 14)
h = boxplot(DATA,GROUP); % use the line handles returned from boxplot, here I call them "h"
WT = load('Ter119WT.mat', 'intensity');
P95H = load ('Ter119P95H.mat', 'intensity');
P95Hrip = load('Ter119P95Hrip.mat', 'intensity');
DATA = [WT;P95H;P95Hrip];
GROUP = [ones(size(WT));2*ones(size(P95H));3*ones(size(P95Hrip))];
figure
Voss
Voss on 14 Apr 2022
Can you upload the mat files?

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!