MATLAB App Designer: How to display a scatter plot on the UIaxes with linear fit and equation of line ?
조회 수: 3 (최근 30일)
이전 댓글 표시
I am migrating my script to App Designer.
Below script (normal script) is ploting a scatter plot with displayed linear fit and equation of line (figure 1).
Normal script:
str = [107.0176, 256.7374, 257.2012, 441.7806, 420.5170, 602.7027, 591.8610, 756.6289, 896.9324];
Ec1 = [23.8829, 19.0262, 28.8904, 22.3871, 29.4871, 24.5282, 29.3028, 26.3303, 24.5477];
createfigure(str,Ec1)
Figure 1:

Above script cannot be written as such when I am migrating to App Designer. Thus I did rewrite the script (App designer script) to get the best possible same outcome but only able to generate as in figure 2. The generated figure has no equation of line displayed and the linear fit need long script for it to be plotted.
App designer script:
str = [107.0176, 256.7374, 257.2012, 441.7806, 420.5170, 602.7027, 591.8610, 756.6289, 896.9324];
Ec1 = [23.8829, 19.0262, 28.8904, 22.3871, 29.4871, 24.5282, 29.3028, 26.3303, 24.5477];
p = polyfit(str,Ec1,1);
f = polyval(p,str);
plot(app.UIAxes3,str,Ec1,'o',str,f,'-')
hold (app.UIAxes3,'on')
legend(app.UIAxes3,'show')
hold (app.UIAxes3,'off')
Figure 2:

Seek your kind help on this very issue.
disclaimer: this script is the simplified version of full script.
댓글 수: 0
답변 (1개)
VBBV
2022년 11월 3일
str = [107.0176, 256.7374, 257.2012, 441.7806, 420.5170, 602.7027, 591.8610, 756.6289, 896.9324];
Ec1 = [23.8829, 19.0262, 28.8904, 22.3871, 29.4871, 24.5282, 29.3028, 26.3303, 24.5477];
p = polyfit(str,Ec1,1);
f = polyval(p,str)
str1 = linspace(min(str),max(str),9)
plot(str,Ec1,'o',str1,f,'-')
댓글 수: 5
VBBV
2022년 11월 3일
str = [107.0176, 256.7374, 257.2012, 441.7806, 420.5170, 602.7027, 591.8610, 756.6289, 896.9324];
Ec1 = [23.8829, 19.0262, 28.8904, 22.3871, 29.4871, 24.5282, 29.3028, 26.3303, 24.5477];
p = polyfit(str,Ec1,1);
f = polyval(p,str);
str1 = linspace(min(str),max(str),9);
y = (vpa(poly2sym([p]),3))
plot(str,Ec1,'o',str1,f,'-')
ax = gca
text(ax,300,26,sprintf('y = %.5fx + %.2f',p(1),p(2)))
참고 항목
카테고리
Help Center 및 File Exchange에서 Creating, Deleting, and Querying Graphics Objects에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!