How can I subplot 3 graphs with errors barr and different characteristics?

15 views (last 30 days)
Dear community, I hope you can help me with this issue:
I need to subplot 3 graphs. Each graph has 2 variables and I need that appears with the same x variable (in this case is "time"). T_A8_C is mean of measurements and T_A8_D is mean of other measurements, and so on. I need 3 subplots: first: T_A8_C with T_A8_D, second: T_C5_C with T-C5_D and third: T_E1_C with T_EA_D
I have this commands:
subplot(2,1,1)
x = linspace(0, 130, numel(T_A8_C));
X = [x;x].';
YA8 = [T_A8_C(:) T_A8_D(:)];
plot(X,YA8)
subplot(2,1,2)
YC5 = [T_C5_C(:) T_C5_D(:)];
plot(X,YC5)
subplot(2,1,3)
YE1 = [T_E1_C(:) T_E1_D(:)];
plot(X,YE1)
err=[T_desvA8_C(:) T_desvC5_C(:) T_desvE1_C(:) T_desvA8_D(:) T_desvC5_D(:) T_desvE1_D(:)];
errorbar(X,Y,err)
hEB=errorbar(X,Y,err);
hEB(1).Color=('red');
hEB(2).Color=('blue');
hEB(3).Color=('black');
hEB(4).Color=('red');
hEB(5).Color=('blue');
hEB(6).Color=('black');
hEB(1).LineStyle=('-');
hEB(2).LineStyle=('-');
hEB(3).LineStyle=('-');
hEB(4).LineStyle=('-.');
hEB(5).LineStyle=('-.');
hEB(6).LineStyle=('-.');
hEB(1).LineWidth=(2);
hEB(2).LineWidth=(2);
hEB(3).LineWidth=(2);
xticks(0:5:130);
title('Cell Temperature Plot')
xlabel('Time (Days)')
ylabel('Cell Temperature (°C)')
legend('A8 Clean','C5 Clean','E1 Clean','A8 Dirty','C5 Dirty','E1 Dirty');
And this message error appears:
Error using subplot (line 332)
Index exceeds number of subplots.
Error in Prueba_TCell (line 79)
subplot(2,1,3)
And doesn´t show the title, labels of each axis, the characteristic width and linestyle and legend.
Please help me with this. =(
Thank you so much!

Accepted Answer

Allen
Allen on 8 Jan 2020
Replace the lines containing the subplot functions with the following:
...
subplot(3,1,1)
...
subplot(3,1,2)
...
subplot(3,1,3)
...
Essentially the subplot functions works by specifying the number of rows (m) and columns (n) of plots to generate in the target figure, followed by the instance (i) or location that you currently want to use for plotting.
e.g. - subplot(3,1,1) states that the arrangement of plots is to be 3 rows by 1 column and you are currently targeting the 1st instance (i.e. the top-left subplot location).

More Answers (2)

Jonathan Bijman
Jonathan Bijman on 8 Jan 2020
Thanks a lot @Allen! Now I get the subplots. But I can´t get that appears the error bar and the other characteristics like width, linestyle,etc. I don´t know how can I fix that.
Do you know something about that?
Thank u again =)
  1 Comment
Allen
Allen on 8 Jan 2020
You need to use the title, label, and legend functions after each use of the plot function. Additionally, you need to set the line characteristics after each plot() as well.
...
subplot(3,1,1)
plot(...)
% Enter errorbar and line charateristics for plot #1
title('...')
xlabel('...')
xlabel('...')
lengend('...')
...
subplot(3,1,2)
plot(...)
% Enter errorbar and line charateristics for plot #2
title('...')
xlabel('...')
xlabel('...')
lengend('...')
...
subplot(3,1,3)
plot(...)
% Enter errorbar and line charateristics for plot #3
title('...')
xlabel('...')
xlabel('...')
lengend('...')
...
You can also set most of the line charateristics directly when using plot(). See the help page for this function. https://www.mathworks.com/help/matlab/ref/plot.html

Sign in to comment.


manju
manju on 6 Aug 2022
  1. Use the given Taylor series as an exponential function. (Refer to the image for e^x)
  2. Compute the error of Taylor series when using 10 and 15 terms for x = 2.
  3. Compute e^x for 10 terms or 15 terms using the series
  4. Compute e^x for x=2 directly
  5. Compare the result of i and ii
  6. Find the appropriate number of terms when the error can be in a range of 0.001 for x = 3.
  1. Implement the given function code and observe the results for any 5 inputs
function [ f g ] = solve( x,y )
f = x .^ -0.5;
g = y + f .* 2;
end
  1. Generate the data and plot the following 5 figures.
  1. Simulate a population of rats for 20 years. The initial population of rats is 10. Each year, 4% of the population of the previous year dies off, and each year exactly 6 new rats are born. Plot the population of rats for 20 years.

Products


Release

R2019b

Community Treasure Hunt

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

Start Hunting!