meshgrid or ngrid?

조회 수: 5 (최근 30일)
ttopal
ttopal 2016년 8월 9일
답변: KSSV 2016년 8월 9일
Hi, I have lately started to use meshgrid and ngrid thanks to the answer to my previous question. But I can not find a way to transform this code to either of them. Here on this code I have one calculationPoint, which normally has to be a meshgrid of -20:20 on both X and Y direction. Any suggestion on how to proceed would be appreciated.
clc;
S = 21;
t = linspace(-pi,pi,S);
knownPoints = [cos(t);sin(t)]; %(x,y)
f = exp(1i*t);
d = zeros (1,S);
calculationPoint = [10;9];
for idx=1:S
tmp1 = calculationPoint(1,1)-knownPoints(1,idx);
tmp2 = calculationPoint(2,1)-knownPoints(2,idx);
d(idx) = sqrt(tmp1^2+tmp2^2);
end
g = d.^2 + 1./d.^3;
z = 1/S*sum(g.*f); % z function is of parameter calculation point

답변 (1개)

KSSV
KSSV 2016년 8월 9일
Your d, g are arrays of same size as t....You can use mesh grid on d/g... Are you looking for some thing like below?
clc;
S = 21;
t = linspace(-pi,pi,S);
knownPoints = [cos(t);sin(t)]; %(x,y)
f = exp(1i*t);
d = zeros (1,S);
calculationPoint = [10;9];
for idx=1:S
tmp1 = calculationPoint(1,1)-knownPoints(1,idx);
tmp2 = calculationPoint(2,1)-knownPoints(2,idx);
d(idx) = sqrt(tmp1^2+tmp2^2);
end
g = d.^2 + 1./d.^3;
[T,G] = meshgrid(t,g) ;
z = 1/S*sum(g.*f); % z function is of parameter calculation point

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by