save CART as fig without displaying

2 次查看(过去 30 天)
I have created a decision tree for classification using fitctree, tree=fitctree(...). I can visualise it using the command view(tree,'Mode','Graph'). I can then use the option "Save as" from the File menu to save the tree as a .fig file. However, I would like to save the tree as .fig directly without the visualisation step. I have tried: tree=fitctree(...); h = view(tree); saveas(h,'filename','fig'); but it doesn't work. I get the error: Error using ClassificationTree/view Too many output arguments. Any ideas how to save a CART tree as .fig, but without displaying it? I would like to be able to do this from the command window, so using the "Save as" from the file menu is not an option.

采纳的回答

Nachiket Katakkar
Nachiket Katakkar 2017-2-24
Although the handle is not readily available as an output of "view", you can obtain the figure handle using the "findall" command. You can then save as a FIG file using the "saveas" command. Here is an example:
% Load data and make a table
load carsmall
tbl = table(Weight,Cylinders,MPG,Origin);
% Fit Classification Tree
tree = fitctree(tbl,'Origin');
% Call the view function
view(tree,'mode','graph');
% Obtain the handle
h = findall(0,'type','figure','Name','Classification tree viewer');
% Save file
saveas(h,'classTree.fig');
This method would still display the tree, but you would be able to save it from the Command Window.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Printing and Saving 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by