Showing posts with label Figure. Show all posts
Showing posts with label Figure. Show all posts
Thursday, 10 September 2015
Thursday, 18 December 2014
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
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
Sunday, 10 November 2013
How to save Matlab graphs/plots with high resolution/quality (suitable for publications)?
Use the export-figure file from:
http://www.mathworks.com/matlabcentral/fileexchange/23629-exportfig
Examples can be found at:
https://sites.google.com/site/oliverwoodford/software/export_fig
Other settings:
% Colour adjustmentsset(gcf, 'Color', 'w'); %background outside the plot
set(gca, 'Color', 'w'); %background of the plot
% Set figure format - Size
% set(gcf,'Position',[xpos ypos scale*width scale*height])
set(gcf, 'Position', [100 100 150 150])
%or,
scrsz = get(0,'ScreenSize'); %returns the screen size
set(gcf, 'Position', [0 0 0.85*scrsz(3) 1*scrsz(4)]);
% Saving figure using export_fig
figName = [fName(1:end-4) '.png'];
saveas(gcf, figName);
export_fig(figName);
% Example:
function [] = SaveAndExportFigure(figName)
set(gcf, 'Color', 'w'); %background outside the plot
set(gca, 'Color', 'w'); %background of the plot
scrsz = get(0,'ScreenSize');
set(gcf, 'Position', [0 0 0.85*scrsz(3) 1*scrsz(4)]);
saveas(gcf, figName);
export_fig(figName);
http://www.mathworks.com/matlabcentral/fileexchange/23629-exportfig
Examples can be found at:
https://sites.google.com/site/oliverwoodford/software/export_fig
Other settings:
% Colour adjustmentsset(gcf, 'Color', 'w'); %background outside the plot
set(gca, 'Color', 'w'); %background of the plot
% Set figure format - Size
% set(gcf,'Position',[xpos ypos scale*width scale*height])
set(gcf, 'Position', [100 100 150 150])
%or,
scrsz = get(0,'ScreenSize'); %returns the screen size
set(gcf, 'Position', [0 0 0.85*scrsz(3) 1*scrsz(4)]);
% Saving figure using export_fig
figName = [fName(1:end-4) '.png'];
saveas(gcf, figName);
export_fig(figName);
% Example:
function [] = SaveAndExportFigure(figName)
set(gcf, 'Color', 'w'); %background outside the plot
set(gca, 'Color', 'w'); %background of the plot
scrsz = get(0,'ScreenSize');
set(gcf, 'Position', [0 0 0.85*scrsz(3) 1*scrsz(4)]);
saveas(gcf, figName);
export_fig(figName);
Subscribe to:
Posts (Atom)