我有数据(以Matlab的图形文件格式),每个数字都包含一条线图,包含两条线(代表EEG曲线),轴,一串标签等。
我想:
我会遍历fig文件并为每个文件执行相同的操作。
是否有可以索引和编辑的图中所有对象的列表?如何使用命令(即没有gui)来访问这些对象?
答案 0 :(得分:3)
Line,lable等是轴的子节点,它本身就是一个数字的子节点。您需要做的是获取要通过此层次结构更改的对象的句柄。
% Get a handle to the figure
hfig = openfig('testfig');
% Get all children of the CurrentAxes. Most of what you want is here.
axes_obj = allchild(hfig.CurrentAxes);
% Edit Axes object according to its type
For ii = 1:length(axes_obj)
switch axes_obj(ii).Type
case 'Text'
% Do something, for example:
axes_obj(ii).String = 'changed';
case 'Line'
% Do something, for example:
axes_obj(ii).MarkerEdgeColor = 'b';
end
end
% Save figure
savefig(hfig, 'testfig')
只需在命令窗口中键入axes_obj(ii)
,即可查看要编辑的对象的所有属性。