I want to plot from -5 to 5 on the x and y, but I am having trouble. Any help?

조회 수: 2 (최근 30일)
Luis Hernandez
Luis Hernandez 2020년 2월 17일
편집: Khalid Mahmood 2021년 4월 14일
I want to plot from -5 to 5 on both the x andy
%mesh
X=-5:.5:5;
Y=-5:.5:5;
[x y]=meshgrid(X,Y);
% calculate
f=exp(-0.25.*sqrt(x.^2+y.^2));
%imagesc
figure(1)
imagesc(f);
colorbar
xlabel('x');
ylabel('y');
title('imagesc with colorbar')
%gradient
[fx,fy]=gradient(f);
figure(2)
quiver(fx,fy)
xlabel('fx');
ylabel('fy');
title('gradient plot')

답변 (2개)

Srivardhan Gadila
Srivardhan Gadila 2020년 2월 20일
Use the imagesc and quiver as follows:
imagesc(X,Y,f);
quiver(x,y,fx,fy);

Khalid Mahmood
Khalid Mahmood 2021년 4월 14일
편집: Khalid Mahmood 2021년 4월 14일
%Hope you need this. I mean just plot mesh also
%mesh
Lim=-5:.5:5; %both x,y have same limits
[x y]=meshgrid(Lim);
% calculate
f=exp(-0.25.*sqrt(x.^2+y.^2));
%imagesc
figure(1)
subplot(211);imagesc(f); subplot(212);mesh(x,y,f)
colorbar
xlabel('x');
ylabel('y');
title('imagesc with colorbar')
%gradient
[fx,fy]=gradient(f);
figure(2)
surf(x,y,fx,fy)%quiver(fx,fy)
xlabel('fx');
ylabel('fy');
title('gradient plot')

카테고리

Help CenterFile Exchange에서 Eigenvalue Problems에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by