1

I have the following code but Im having issues trying to make this plot the standard deviation for the vector 'Ibig'. When i run the code i get an error saying that 'x2' in the 8 isnt the same vector size. How can i fix this problem or is there another way to plot the standard deviation?

y = Ibig;
x = 1:numel(y);
std_dev = std(y);
curve1 = y + std_dev;
curve2 = y - std_dev;
x2 = [x, fliplr(x)];
inBetween = [curve1, fliplr(curve2)];
fill(x2, inBetween, 'g');
hold on;
plot(x, y, 'r', 'LineWidth', 2);

What y looks like

4
  • The question is unclear for me. What does "Im having issues trying to find x2" mean? What is x2? What issues do you have? Commented Apr 3, 2021 at 18:17
  • Apologies, i have updated the description @ThomasSablik. Essentially i need to figure out a way to fill in the area between two line plots (In this case curve1 and curve2). Commented Apr 3, 2021 at 18:36
  • What format does y have? Your code works if y is a row vector (1 x n). It doesn't work for column vectors or arrays with higher dimension. Commented Apr 3, 2021 at 18:38
  • @jabaa have updated the description to show that its a (n x 1) column vector. Is there anyway that i can change this so that it is a row vector or is there another way to plot this as a standard deviation? Commented Apr 3, 2021 at 18:47

1 Answer 1

2

Your code works with row vectors but not with column vectors. In your image you are showing a column vector. You have to transpose it:

y = Ibig.';
x = 1:numel(y);
std_dev = std(y);
curve1 = y + std_dev;
curve2 = y - std_dev;
x2 = [x, fliplr(x)];
inBetween = [curve1, fliplr(curve2)];
fill(x2, inBetween, 'g');
hold on;
plot(x, y, 'r', 'LineWidth', 2);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.