Code seems to not be printing out the value I need, as well as not graphing points on the figure. Need help, I don't know how to fix this.
1 view (last 30 days)
Show older comments
clear
clc
m1=1000;
m2=500;
m3=200;
rp=87;
r2=[58.7 27.8 20 59 30 31.2 68.5 67 34 60 39 50.3 50 45.3 45]';
r3=[12.89 20.65 226 120 217 193.1 91.6 110 197.5 166 158.3 142.1 150 176.5 122]';
G = ones(length(m1), 2);
G(:,2) = m1;
m = G \ m2
m_b=(m2/rp)*((-m1)/(rp));
sigma = sqrt(sum((m2-G*m).^2)./(length(m1)-2));
se1 = sigma.*sqrt(1./((length(m1)+mean(m1)^2/((length(m1)-1)*std(m1)^2))));
se2 = sigma.*sqrt(1./((length (m1)-1)*std(m1)^2));
Ci1=tinv(.975,length(m1)-2).*se1;
Ci2=tinv(.975,length(m1)-2).*se2;
% creating a line of best fit
X = [min(m1);1e-3;max(m1)]';
Y = m(1,1) + m(2,1).*X;
SE=sigma.*sqrt(1/length(m1)+(X-mean(m1)).^2./((length(m1)-1)*std(m1).^2));
Ci=tinv(.975,length(m1)-2).*SE;
figure(1)
clf
plot(m1, m2, 'ob')
hold on
% plotting the conidence intervals
plot (X, Y, 'R')
plot(X,Y+Ci,'g--')
plot(X,Y-Ci,'g--')
hold off
xlabel('$$-$$','interpreter','latex')
ylabel('$$-)$$','interpreter','latex')
print(figure(1), '-dpng', 'figure1')
2 Comments
Star Strider
on 9 Dec 2018
I cannot read the image. As is, it is too small, and when I enlarge it, it iss not distinct enough to read.
I am guessing that you are dong some sort of regression, and then want to plot the data, regression, and oconfidence intervals.
Please describe what you want to do.
Answers (2)
Star Strider
on 9 Dec 2018
Now I can read it, although understranding your notes remains a problem.
You still have not described what you want to do with ‘r2’ and ‘r3’.
If you want to calculate the copnfidence intervals on the linear regression and the parameters, use the Statistics and Machine Learning Toolbox regress (link) function. Calculating the confidence intervals on a regression involves calculating the covariance matrix of your data. It is easier to let regress do it.
4 Comments
Star Strider
on 9 Dec 2018
Please note that:
m_b=(m2/rp)*((-m1)/(rp));
does not answer my question, since these are scalar quantities, anbd appear to be unrelated to ‘r2’ and ‘r3’ that appear to be data.
Please be specific. Tell me what your data are, and what you want to do with them.
Image Analyst
on 9 Dec 2018
"seems to not be printing out the value" <==== Use fprintf() or disp() or leave off semicolons to print to the command window. Don't use print() like you had.
See Also
Categories
Find more on Subplots 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!