Showing posts with label surf. Show all posts
Showing posts with label surf. Show all posts

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

Wednesday, 23 October 2013

How to plot the shadow in the 'surf' plot in Matlab?

1. Follow these hints: Thanks to the 'shadowplot' function from Mathworks.
z = magic(100);
surf(z);
shading interp;
shadowplot x;
shadowplot y;

xlabel('xMagic','rot', 14,'fontweight','bold','fontsize',12); 
ylabel('yMagic','rot', -20,'fontweight','bold','fontsize',12);
zlabel('zMagic','fontweight','bold','fontsize',14);

Example of Shadow plot:


2. The shadowplot x and shadowplot y demand 'x' and 'y' to be monotonically increasing. Due to Matlab's floating point representation problem (clearly explained HERE), we will not get monotonically increasing number even when we use: dx = 0: 0.01:1; This can be checked by:

dx = 0:0.01:1;
figure;
plot(diff(dx));

This will become a problem to use 'shadowplot'. One method that could be used is:

a. Plot the 3-D space
surf(corrValues); % instead of surf(x,y, corrValues);
shading interp;
shadowplot y;
shadowplot x;

%Now the plot x and y indices will be integers starting from 1 to size(corrValues) respectively. Off course, there will be (0,0) point but corrValues are not pointed at this point.


b. Now to have the x- and y-axis labelling as desired, instead of integers, following method could be used:

% Get the string from the number array
for ii = 1:2:length(xx)
   xTickLabel1(ii).a = num2str(xx(ii), 4);
end

xlbl = {xTickLabel1.a};

for ii = 1:1:length(yy)
 yTickLabel1(ii).a = num2str(yy(ii), 4);
end

ylbl = {yTickLabel1.a};

% Set the grid-lines -- x and y indices where grid lines to be shown
set(gca, 'XTick',[1:1:length(xx)]);
set(gca, 'YTick',[1:1:length(yy)]);
% Label the grid-lines that are selected above.
set(gca,'XTickLabel',xlbl)
set(gca,'YTickLabel',ylbl)