tevez
tevez

Reputation: 31

Working with meshgrid in MATLAB

How would you replace the following by meshgrid?

N=.33;
P=.45;

for i =1:10
    for j=1:20
        x0=i+N;
        y0=j+P;
        f(i,j)=exp(x0+y0);
    end
end

Upvotes: 3

Views: 2019

Answers (1)

ShinTakezou
ShinTakezou

Reputation: 9661

I think something like

[X, Y] = meshgrid(1:10, 1:20);
Z = exp( (X+N) + (Y+P) );
% surf(X, Y, Z);

read here

edit

as user requested (if I've understood well):

[X, Y] = meshgrid(1:10, 1:20);
X1 = X + N; Y1 = Y + P; 
Z = exp( X1 + Y1 );
% surf(X1, Y1, Z);

Upvotes: 5

Related Questions