CiaranWelsh
CiaranWelsh

Reputation: 7689

How to get the ylabel function in Matlab working correctly

So I'm trying to use this code to generate plots:

%initialize some variables
antibodies = {'Rel-A','p-Rel-A','IkBa','p-IkBa','A20'};
titles = {'PBS','GOX','TNF','L','M','H'};
x_axis = {'1h','3h','6h'};
y_axis = 'Optical Density';

%create figure
figure('name','Time Course,PBS,Cyt')
for j=1:5,
   subplot(5,1,j)
   errorbar(avg_time_course_data{2}(j,1:3),avg_time_course_error{2}(j,1:3))
   set(gca, 'XTick', 1:6, 'XTickLabel', x_axis)
   title(antibodies(j)) 
   ylabel(y_axis);   
end

When I run this script however I get the plots but with no Y label! Does anybody know why?

Upvotes: 1

Views: 224

Answers (1)

m_power
m_power

Reputation: 3204

I changed some lines in your code. I also tested with errorbar(rand(1,10), rand(10,1)).

%initialize some variables
antibodies = {'Rel-A','p-Rel-A','IkBa','p-IkBa','A20'};
titles = {'PBS','GOX','TNF','L','M','H'};
x_axis = {'1h','3h','6h'};
y_axis = 'OD'; % I made the string shorter, because it was overlapping the other ylabel on my screen.

%create figure
figure('name','Time Course,PBS,Cyt')
for jj=1:5,
   subplot(5,1,jj)
   errorbar(rand(1,10), rand(10,1))
   set(gca, 'XTick', 1:6, 'XTickLabel', x_axis)
   title(antibodies(jj)) 
   set(get(gca,'YLabel'), 'String', y_axis); % The code now use a different method for setting the ylabel string.   
end

Let me know if it helps you.

Upvotes: 1

Related Questions