Using errorbar for multi-column datasets without loop
5 views (last 30 days)
Show older comments
I have two datasets X and Y and the respective error values of Y stored in errY (each having the size: 100 x 3). Naturally, I can obtain three plots of these datastes using plot(X,Y), but when I try to add error bars by writing
errorbar(X,Y,errY)
I see the error message:
Error using errorbar>checkSingleInput (line 266)
YNegativeDelta must be empty or the same size as YData.
Error in errorbar (line 135)
yneg = checkSingleInput(neg, sz,'YNegativeDelta');
I know this can be done easily by using a loop but since this has to be repeated multiple times I prefer the code to be compact by possibly preventing a loop. How can this be done?
0 Comments
Answers (1)
dpb
on 15 Jun 2018
I get the same error if I try to use a single error value for all y regardless of number of columns; I thought previous versions let you specify a single error value as just one value per column, too, but at least now back thru R2014b behavior is that must be same as for all.
>> x=[1:10].';x=[x x]; y=100*randn(size(x)); % some data
>> yerr=rand(1,2); % constant error each column
>> errorbar(x,y,yerr)
Error using errorbar>checkSingleInput (line 266)
YNegativeDelta must be empty or the same size as YData.
Error in errorbar (line 135)
yneg = checkSingleInput(neg, sz, 'YNegativeDelta');
>> errorbar(x(:,1),y(:,1),yerr(1))
Error using errorbar>checkSingleInput (line 266)
YNegativeDelta must be empty or the same size as YData.
Error in errorbar (line 135)
yneg = checkSingleInput(neg, sz, 'YNegativeDelta');
>>
That fails for either multiple columns or single column; that seems rude altho is documented.
Make the error vector be same length as is y--
>> errorbar(x(),y(),repmat(yerr,length(y),1))
>>
This succeeds per documentation altho I agree it seems quite user unfriendly to have to duplicate constants.
I guess they didn't want to go to the trouble of parsing whether the size(err) matched up to the number of columns and try to determine whether was legal and just what meant since there are both x- and y-errors possible and one could have fixed in one dimension but not the other so there are a "veritable plethora" of choices that could be legal. This way, has to match and they can count inputs to decide.
I think I'd still suggest an enhancement request and see what ensues--not likely to be implemented methinks, however.
0 Comments
See Also
Categories
Find more on Errorbars in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!