plotting a mean response curve

4 views (last 30 days)
Jason
Jason on 18 Jul 2017
Commented: Star Strider on 20 Jul 2017
Apologies - I am a Matlab newbie and have spent a few hours looking for online help with this. All I want to be able to do is to pull in (or generate) numerous "dose-response" datasets (each one a pair of vectors, one "x", the other "R" (the response). The x vector is common to all. I want to: 1. Plot all curves 2. Plot the mean response curve 3. Show standard deviations at each x point
I have tried:
x=[0, 50, 200, 500]
R1=[10, 30, 90, 200];
R2=[10, 15, 60, 90];
R3=[1, 5, 40, 75];
Rave = mean([R1 R2 R3],2); % assuming Ys are column vectors and defines mean of the response vectors
plot(x,R1,'b')
hold on
plot(x,R2,'b')
hold on
plot(x,R3,'b')
plot(x, Rave,'-s','MarkerSize',5,'MarkerEdgeColor','red','MarkerFaceColor',[1 .6 .6]) %// mean of all blue curves) %plots the 3 vectors in blue
This is not working (in the sense that the means are not right). I am sure this is simple so apologies in advance but any help hugely welcome

Accepted Answer

Star Strider
Star Strider on 18 Jul 2017
‘assuming Ys are column vectors and defines mean of the response vectors’
They are not, at least in the code that you posted. If you want them as column vectors, use semicolons ‘;’ that will concatenate the elements of the vectors vertically instead of commas ‘,’ that will concatenate them horizontally.
This is probably what you want:
x=[0, 50, 200, 500]
R1=[10; 30; 90; 200];
R2=[10; 15; 60; 90];
R3=[1; 5; 40; 75];
Rave = mean([R1 R2 R3],2);
figure(1)
plot(x,R1,'b')
hold on
plot(x,R2,'b')
hold on
plot(x,R3,'b')
plot(x, Rave,'-sr','MarkerSize',5,'MarkerEdgeColor','red','MarkerFaceColor',[1 .6 .6]) %// mean of all blue curves) %plots the 3 vectors in blue
The other change I made was to plot the line for the mean entirely in red to make it easier to see.
  10 Comments
Jason
Jason on 20 Jul 2017
You are an absolute star - thank you very much.
Star Strider
Star Strider on 20 Jul 2017
Thank you! As always, my pleasure.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!