Matlab function input define

1 回表示 (過去 30 日間)
Moli Wang
Moli Wang 2017 年 3 月 29 日
編集済み: Walter Roberson 2017 年 3 月 30 日
I want to define a matlab function that can generate the deformation gradients etc...so I wrote something like this
function [F,R,U]=deformationgradients[X,Y,Z]
However, I want X,Y,Z of the inputs could be any functions like X=ax^2 or X=xyz or X=z+6; Y=ax+by or Y=6z+3x; Z=x^2 or Z=y+z; where capital X,Y,Z are the total displacements in x,y,z direction.
How can I do that?

回答 (1 件)

Richard Zappulla
Richard Zappulla 2017 年 3 月 30 日
In my opinion, I would look at passing function handles into your function for X, Y, or Z. The workflow would look something like this:
X = @(x,y,z)(x.*y.*z);
Y = @(x,z)(6.*z + 3.*x);
Z = @(y,z)(y+z);
[F,R,U] = deformationgradients(X,Y,Z,x,y,z);
If you plan on handling vector data, note the ".*" (element-wise multiplication) inside each function. If you are planning on performing matrix-multiplication, remove the ".". Then inside your function, it could look something like:
function [F,R,U] = deformationgradients(X,Y,Z,x,y,z)
someVar1 = X(x,y,z);
someVar2 = X(x,y,z) + Y(x,z);
.
.
.
end
where X,|Y|,and Z are the function handles and x,|y|, and z are data.
Hope this is what you are looking for.
  1 件のコメント
Stephen23
Stephen23 2017 年 3 月 30 日
編集済み: Stephen23 2017 年 3 月 30 日
It would probably be simpler to define each function to accept all of x, y, and z, even if they are not used:
X = @(x,y,z)(x.*y.*z);
Y = @(x,y,z)(6.*z + 3.*x);
Z = @(x,y,z)(y+z);
This will make calling them inside the function consistent, and make the function more versatile.

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

カテゴリ

Help Center および File ExchangeCalendar についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by