scaling axes on plot

3 visualizaciones (últimos 30 días)
Catherine Law
Catherine Law el 21 de Mzo. de 2022
Respondida: Star Strider el 21 de Mzo. de 2022
I have a gabor function in terms of x and y (my question is in bold after the explanation of what I am doing)
(for reference):
%set up variables
sigmax = 2;
sigmay = 2;
k = 1;
phi = 0;
initial = -5; %initial degrees as in fig 2.10
final = 5; %final degrees as in fig 2.10
d = 0.01; %steps to compute through
x = initial:d:final; %vector for x values -5>5 degrees as in fig 2.10
y = initial:d:final; %vector for y values -5>5 degrees as in fig 2.10
Ds = zeros(length(x),length(y)); %vector for Ds
%gabor function
for i = 1:length(x)
for j = 1:length(y)
Ds(i,j) = (1/(2*pi*sigmax*sigmay))*(exp(-(((x(i)).^2)./(2*((sigmax).^2)))-(((y(j)).^2)./(2*((sigmay).^2)))))*(cos(k*(x(i))-phi));
end
end
I need to plot this function as an image:
%plot image
figure (1)
imagesc(Ds)
xlabel ('x (degrees)')
ylabel ('y (degrees)')
title('Gabor function of spatial receptive field')
Which produces the following plot:
As you can see, the axes on this plot have values of 0:1000 (the total number of values in Ds), but I need them to be the values of x and y (-5:5 degrees) in the steps d I specified.
Is there a way I can scale the axes (or any other method to achieve the desired result), so that the plot axes are labeled -5:5 instead of 0:1000?
thank you :)

Respuestas (1)

Star Strider
Star Strider el 21 de Mzo. de 2022
There are several options, the easiest of which is to use the surf function rather than imagesc to plot it.
%set up variables
sigmax = 2;
sigmay = 2;
k = 1;
phi = 0;
initial = -5; %initial degrees as in fig 2.10
final = 5; %final degrees as in fig 2.10
d = 0.01; %steps to compute through
x = initial:d:final; %vector for x values -5>5 degrees as in fig 2.10
y = initial:d:final; %vector for y values -5>5 degrees as in fig 2.10
Ds = zeros(length(x),length(y)); %vector for Ds
%gabor function
for i = 1:length(x)
for j = 1:length(y)
Ds(i,j) = (1/(2*pi*sigmax*sigmay))*(exp(-(((x(i)).^2)./(2*((sigmax).^2)))-(((y(j)).^2)./(2*((sigmay).^2)))))*(cos(k*(x(i))-phi));
end
end
%plot image
figure (1)
surf(x,y,Ds, 'EdgeColor','none')
colormap(turbo)
view(0,90)
xlabel ('x (degrees)')
ylabel ('y (degrees)')
title('Gabor function of spatial receptive field')
.

Categorías

Más información sobre Line Plots en Help Center y File Exchange.

Productos


Versión

R2021b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by