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
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
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.