필터 지우기
필터 지우기

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 (최근 30일)
lab5.jpg
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
Star Strider
Star Strider 2018년 12월 9일
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.
ktar
ktar 2018년 12월 9일
편집: ktar 2018년 12월 9일
There is a model equation (included in code) that is supposed to give me the slope of the line/ value for m. Also I want my figure to have dots (data points form my data).
lab_5.jpg

댓글을 달려면 로그인하십시오.

답변 (2개)

Star Strider
Star Strider 2018년 12월 9일
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
Star Strider
Star Strider 2018년 12월 9일
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
Image Analyst 2018년 12월 9일
"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.
  댓글 수: 1
ktar
ktar 2018년 12월 9일
편집: ktar 2018년 12월 9일
can you add it to my code that I posted, I'm not an expert and dont wanna make a mistake. Also thank you for your help! Also will this print out data points (blue dots) on my figure and give me the value for m?

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Subplots에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by