To store plotregression value in a variabe
显示 更早的评论
is it possible to store the regression (R) value in a variable
%%plots the linear regression of targets relative to outputs.
plotregression(targets,outputs)
采纳的回答
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.
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
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..
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)
