Calling a function with vector as input

I have a function: function [U] = FE (nelx, nely, o) As nelx=4, nely=4 and o=2 I could simply call it by writing FE(4,4,2). But now I have another input function [U] = FE (nelx, nely, o, k) k is a 16x1 vector. As its not a scalar value, its an array of 16 values. How do I call this function? FE(4,4,2,?)

4 件のコメント

Adam
Adam 2018 年 2 月 6 日
編集済み: Adam 2018 年 2 月 6 日
FE(4, 4, 2, k )
It is generally a good habit to call functions with named inputs rather than hard-coded numbers anyway, but that is opinion rather than fact.
Obviously in this case your function has to support a vector argument in the 4th position.
Ahmad Hasnain
Ahmad Hasnain 2018 年 2 月 7 日
Actually, that is the problem, I can't figure it out that how to add support for vector argument in 4th position.
Stephen23
Stephen23 2018 年 2 月 7 日
編集済み: Stephen23 2018 年 2 月 7 日
"How do I call this function? FE(4,4,2,?)"
FE(4,4,2,k)
Why do you think that you need to do something special? Scalar values are arrays too, and you don't seem to be worried about passing them to your function. What is the real problem?
"I can't figure it out that how to add support for vector argument in 4th position."
So write the function so that it accepts a vector for its fourth argument. This has nothing to do with how the function is called.
Ahmad Hasnain
Ahmad Hasnain 2018 年 2 月 7 日
OK, thanks. I will try it in my program. I am using Matlab after maybe 8 years. So with practice, I will get better.

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

回答 (0 件)

カテゴリ

質問済み:

2018 年 2 月 6 日

コメント済み:

2018 年 2 月 7 日

Community Treasure Hunt

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

Start Hunting!

Translated by