To store plotregression value in a variabe
이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
이전 댓글 표시
0 개 추천
is it possible to store the regression (R) value in a variable
%%plots the linear regression of targets relative to outputs.
plotregression(targets,outputs)
채택된 답변
Mehmed Saad
2020년 4월 3일
Suppose the example given below
it is matlab example
[x,t] = simplefit_dataset;
net = feedforwardnet(10);
net = train(net,x,t);
y = net(x);
v =figure,
plotregression(t,y,'Regression')

%% To get Data
Data_X = v.Children(3).Children(1).XData;
Data_Y = v.Children(3).Children(1).YData;
%% To get Fit
Fit_X = v.Children(3).Children(2).XData;
Fit_Y = v.Children(3).Children(2).YData;
%% To get YeqT
댓글 수: 7
actually i want to store "R" value in some variable.
Mehmed Saad
2020년 4월 4일
편집: Mehmed Saad
2020년 4월 4일
you mean the R value shown in title?
if yes, try this
str =v.Children(3).Title.String;
R =str2double(str(find(str=='=')+1:end));
2nd way is
[R,~,~] = regression(t,y);
can you explain briefly..how to use those commands with exAmple..useusally i use plotregression(t,y,'Regression') command..i want to store R value which is shown on figure top..plese find attached figure for more clarity. in that R=0.36494 i want to store in some varaible
Mehmed Saad
2020년 4월 6일
편집: Mehmed Saad
2020년 4월 6일
The Long Method
When you use plotregression command, it plots 3 Things
- Data
- Fit
- Y = T
Along with that there are titles, xlabel, ylabel and legends
We have the figure handle (we saved it in a variable named v)
v = figure;
plotregression(t,y,'Regression')
the other way to get handle is
v = plotregression(t,y,'Regression');
plotregression commands gives you figure handle as an output too.
After plotregrssion plots the figure, we access its handle as all the data related to that figure is saved in that handle. Remeber once you close the figure you cannot access the data anymore.
Type the following in command window
v.Children

You will se this, it shows that your figure has 3 children
- UIControl
- Legend
- Axes
We are interested in Axes as regression value is stored in axes title
Type the following in command window
v.Children(3)
you will se that this is the axes handle and you have all the properties of axes like title, xlabel, ylabel etc. Also all the values of Data, Fit an Y=T are stored in axes childrens.
Type following in command window to see Title properties
v.Children(3).Title
you will see that it's a text type and all info is shown. What we want is the string value Which is
'Regression: R=0.2145'
acess this string via
v.Children(3).Title.String
your ans will be
'Regression: R=0.2145'
Store it in some variable as i did in str in the above answer
str = v.Children(3).Title.String;
Now what you want is the value written after equal to sign, so find the equal to sign in str using following command
ind=find(str=='=');
now it will tell you the location of equal to in str
go to next index and you R value starts
R_in_str =str(ind+1:end);
Now this will give you the value of R but in the form of string
'0.2145'
convert it into double
R=str2double(R_in_str)
Your R value is Ready
The Short Method
Remeber that you can access R value directly using regression command. Go to help and type regression, it has the following sytax
[r,m,b] = regression(t,y)
when r is the regresson value you are getting on your plot title
so simply type
[R,~,~] = regression(t,y);
and your R value is in your hand
thanq you so much sir..it help me a lot ...actually.. i need to store R value for 200 iterations for each iteration.. i want to check how much R value.. may it help me a lot..
cheers
Rodolfo
2021년 9월 26일
Awesome. I was searching for this since July.
Thank you
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Grid Lines, Tick Values, and Labels에 대해 자세히 알아보기
제품
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
