How to plot using errorbar but the error bar only in every 5 points
27 次查看(过去 30 天)
显示 更早的评论
I want to plot a matrix (x,y,erro) which has 1000 rows.
Case_1: When I use errorbar it is very hard to see the original line
Case_2: If I plot every 20 steps I lose some infos
Case_3: If I plot the matrix twice ('errorbar' and 'plot') the two lines of the plots differ.
See the image.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1267985/image.png)
I use actually a legend, so it is important for me to have the errorbar as a line (I mean '-')
How can plot the whole matrix with only a few errorbars?
0 个评论
回答(1 个)
dpb
2023-1-18
First, 3) above isn't so -- if you plot the same data with plot() and with errorbar() the two lines will overlap identically; the problem in that figure is you're comparing 2) to 1) -- plot() and friends draw straight lines between the plotted points; if there's sufficient curvature between the points as in your examples above, then when overlay with more points, then the difference does show up.
To do what you want wasn't foreseen by TMW with a builtin option so you'll have to do it yourself but it's not difficult...from an example for errorbar()...
x = linspace(0,2,1000);
y = exp(x);
err = zeros(size(y));
N=100;
ixErr=1:N:numel(y);
err(ixErr) = 0.3*y(ixErr);
hEB=errorbar(x,y,err);
Adjust N as wished to pick as many as you wish...oh. Forgotted about 'CapSize' -- it still draws the vertical line caps for all the points even though the error value is zero--bummer.
In that case, it's probably simpler to not draw the line for errorbar but only with the original plot().
figure
hL=plot(x,y,'b-');
hold on
hEB=errorbar(x(ixErr),y(ixErr),err(ixErr),'b');
You may have to create a fake errorbar with no actual data that uses the line style and color you want the legend to be to avoid the previous artifact of different line segments between the actual and errorbar.
Dealing with this more cleanly would seem a worthwhile enhancement request for errorbar.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Errorbars 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!