Showing posts with label YTicklabel. Show all posts
Showing posts with label YTicklabel. Show all posts

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)

Tuesday, 22 October 2013

How to give names to each indices of an axis in Matlab?

Taken from Matlab help:

x = -pi:.1:pi;
y = sin(x);
p = plot(x,y)

set(gca,'XTick',-pi:pi/2:pi)

set(gca,'XTickLabel',{'-pi','-pi/2','0','pi/2','pi'})

xlabel('-\pi \leq \Theta \leq \pi')

ylabel('sin(\Theta)')

title('Plot of sin(\Theta)')

How to change the GRID size and Grid labels (of x, y, and z axis indices) in Matlab Plots?

1 . Simplest command is:

>> grid minor


2. If we need to customize the grid-line locations, then

a. Equal spacing:

set(gca,'xtick',[0:13:100])
set(gca,'ytick',linspace(-50,50,0))


b. Unequal spacing

xGrid = [-5 -2 -0 4 6 9]; %This need not cover the entire range of x. Where ever %grid-lines are needed we can have


set(gca,'ytick',[-50:2:0])

set(gca,'xtick',xGrid)

c. Example of playing with grid size and grid labels
%Code search space (x-axis) indices
xx = codeChipInd-1;
for ii = 1:2:length(xx)
  xTickLabel1(ii).a = num2str(xx(ii).*(fCode/fSamp), 4);
end
xlbl = {xTickLabel1.a};

%Frequency search space (y-axis) indices
yy = freqSearchRange(1:1:end);
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
%Define the grid-line locations
set(gca, 'XTick',[1:1200:length(xx)]); % selecting every 1200 samples (100 chips) (12.276 MHz Fs=> 12 samples per code)

set(gca, 'YTick',[1:10:length(yy)]); %selecting every 10 frequency bin

% Label the grid-lines that are selected above.
set(gca,'XTickLabel',xlbl(1:1200:end))
set(gca,'YTickLabel',ylbl(1:10:end))


GPS Acquisition: Delay and Frequency search space