使用matlab的fitlm制作一些线性模型。根据文档,我可以让它绘制模型,并在命令窗口中显示模型的详细信息。有没有办法可以在同一张图中同时显示模型和细节?
例如
%make the model
mdl = fitlm(X,comp);
%plot the mdl
subplot(1,2,1)
plot(mdl)
%Display the details
subplot(1,2,2)
%stuff that appears in command window here
Fitlm 文档:https://au.mathworks.com/help/stats/fitlm.html
更新 - 我想在子图中显示的是“mdl.coefficients”,我可以用它来绘制
fig = uifigure;
uit = uitable(fig,"Data",mdl.Coefficients);
但是,当我尝试将其放入子图中时,出现此错误:
Error using uitable
Functionality not supported with figures created with the figure function. For more information, see Graphics Support in App
Designer.
Error in uitable (line 53)
thandle = builtin('uitable', varargin{:});
Error in regressionmodelling_all (line 216)
uit = uitable("Data",mdl.Coefficients);
所以也许这是不可能的?不支持功能?
您可以将轴(在本例中为
subplot
轴)传递到 LinearModel 对象的 plot
函数中,因此
ax = subplot(1,2,1);
plot(mdl, ax);
您可以将 fit 中的命令窗口输出粘贴到
annotation
中。自 2021a 起,您可以使用 formattedDisplayText
捕获来自 disp(mdl)
的命令窗口输出,因此我们有
str = formattedDisplayText( mdl, 'SuppressMarkup', true );
annotation( 'textbox', 'string', str, 'fontname', 'consolas', ...
'Units', 'norm', 'position', [0.5,0.1,0.48,0.8], 'interp', 'none' );
如果您没有安装 Consolas 字体,您可以依靠
'fontname', 'fixedwidth'
,或者根本不使用固定字体,但您的表格不会那么整齐。
输出图: