フィルターのクリア

decide the size of matrix returned by gradient function

1 回表示 (過去 30 日間)
Sanjana Singh
Sanjana Singh 2020 年 5 月 27 日
コメント済み: Sanjana Singh 2020 年 5 月 27 日
I want to find gradient of a function (x,y) in a loop and want to get a matrix of 10x10 size as the gradient matrix. I tried using - [___] = gradient(F,h) to set the distance between each point with different values of h. It doesn't seem to work and only returns a 100X100 matrix whatever I try (In the code below I get a 100x100 matrix for vfy1 and vfx1. How do I make the gradient command return only a 10X10 matrix?
Code-
x_grid = linspace(1,3,10);
y_grid = linspace(1,3,10);
for i = 1:1:length(x_grid)%rows
x = x_grid(i);
vpx_0 = 5;% initialize particle velocity in x and y directions
vpy_0 = 0;
for j = 1:1:length(y_grid) %columns
y = y_grid(j);
[vfy1,vfx1] = gradient(psi,10); % here is the gradient command
vfy= -1*vfy1;
vfx = vfx1;
vpx(i,j) = sqrt((vpx_0).^2 + 2*g(1)*x);
vpy(i,j) = -1*sqrt(vpy_0.^2 + abs(2*g(2)*y));
vpx_0 = vpx(i,j);
vpy_0 = vpy(i,j);
vfx_sum = vfx_sum + vfx;% has been pre-allocated (not shown here)
vfy_sum = vfy_sum + vfy;% has been pre allocated (not shown here)
end
end
  4 件のコメント
Rik
Rik 2020 年 5 月 27 日
As psi is a 100x100 array, so is the output of gradient. The only thing the second input does is scaling the output. If you want a 10x10, you will have to enter a 10x10 matrix or downsample the result.
Sanjana Singh
Sanjana Singh 2020 年 5 月 27 日
Thank you, I didn't realize that. This worked!

サインインしてコメントする。

回答 (0 件)

カテゴリ

Help Center および File ExchangeGraph and Network Algorithms についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by