Saturday 7 December 2013

How to load the Matlab figure and extract data from the figure?

% To load figure

h = hgload('RectangularChipShape.fig')


get(h) % lists all the properties linked to this class

set(h) % lists all the properties that can be configured


Few examples:

set(gca,'fontsize',26);

hline = findobj(gcf, 'type', 'line');
hData = findobj(gcf, 'type', 'data');
set(hline,'LineWidth',4)
set(hline,'LineStyle',':')

idx = [4 5];
set(hline(idx),'Marker','*')


%To extract the data from the figure

axesObjs = get(h, 'Children'); %axes handles
dataObjs = get(axesObjs, 'Children'); %handles to low-level graphics objects in axes


objTypes = get(dataObjs{2});
xdata = get(dataObjs{2}, 'XData'); %data from low-level grahics objects
ydata = get(dataObjs{2}, 'YData');

%To extract data from Surf/Mesh plot
m = magic(10);

figure; h1 = mesh(m); % works for 'surf' also

h12 =gcf; % returns the figure number
 
h1Children = get(h12,'Children');
h1Chotas = get(h1Children,'Children'); % this is equal to h1
xD = get(h1Chotas,'xdata')
yD = get(h1Chotas,'ydata')
zD = get(h1Chotas,'zdata'


% Detailed explanation is available at:

http://www.mathworks.com/help/matlab/learn_matlab/understanding-handle-graphics-objects.html

No comments:

Post a Comment