There is anyway that I can plot a graph like this in MatLab with standard deviation ?

4 views (last 30 days)
MarKf on 6 Sep 2023
Likely yes.
Not sure tho what you mean with "stadard deviation". As in, you can easily calculate it with stdev = std(data) and you can visualize it in the graph with text (btw, also not sure what Y = 10,657 x 10,222 means), but do you mean SError? do you want the std of the data visualized (like errorbars on the points)? do you want to use std as a variable (like y, and then do a regression on that)? or you want to have the residuals plotted? or do you want the confidence bounds of the regression?
You can do all that and more.
Vitor on 6 Sep 2023
I wanna errobars on the points with this middle line, but I don t know the function that I have to use

Sign in to comment.

Answers (2)

Image Analyst
Image Analyst on 6 Sep 2023
Do you mean like the "errorbar" LinePlot shown about half way down the page here:

MarKf on 6 Sep 2023
Edited: MarKf on 12 Sep 2023
n = 15; x = randn(n,1); y = randn(n,1);
sx = std(x); sy = std(y); %maybe non-randn data will have smaller std
lregsrts = regstats(y,x,'linear'); %edit: y first in this function
betal = lregsrts.beta; [X, ixd] = sort(x); %fitlm would be faster, but you can find that example everywhere
Y = ones(size(X))*betal(1) + betal(2)*X;
scatter(x,y,50,'kd','filled'); %diamonds (romboids, kites) as in OP figure
hold on
annotation('textbox',[.15 .2 .1 .1] ,'string',...
['R^2 = ' num2str(lregsrts.rsquare) newline 's_x = ' num2str(sx)...
newline 's_y = ' num2str(sy)],'LineStyle','none') %also text
box on, grid on, set(gca, 'YGrid', 'on', 'XGrid', 'off'), hold off% as in OP figure
Edit: This is what was asked but I feel that this is not what they wanted anyway, it's redundant and uncommon. Typical errorbars on a line of data e.g. obtained by averagin (but then not a regression, unless it's not std) it'd be more likely.


Find more on Data Distribution Plots 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!