scaling axes on plot

조회 수: 2 (최근 30일)
Catherine Law
Catherine Law 2022년 3월 21일
답변: Star Strider 2022년 3월 21일
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 :)

답변 (1개)

Star Strider
Star Strider 2022년 3월 21일
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')
.

카테고리

Help CenterFile Exchange에서 Surface and Mesh Plots에 대해 자세히 알아보기

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by