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)
採用された回答
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 件のコメント
veeresh g
2020 年 4 月 3 日
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
veeresh g
2020 年 4 月 6 日
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..
Mehmed Saad
2020 年 4 月 6 日
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!Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の 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)
