meshgrid or ngrid?
조회 수: 5 (최근 30일)
이전 댓글 표시
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
댓글 수: 0
답변 (1개)
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
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Surface and Mesh Plots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!