Shaun
Shaun

Reputation: 45

Plotting standard deviation on MATLAB

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

Upvotes: 1

Views: 1042

Answers (1)

user15388024
user15388024

Reputation:

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);

Upvotes: 2

Related Questions