フィルターのクリア

How to use cell as input arguments of a function?

12 ビュー (過去 30 日間)
muhammad muda
muhammad muda 2019 年 10 月 7 日
編集済み: meghannmarie 2019 年 10 月 7 日
I have a cell array C = {[1 2 3],[4 5 6],[7 8 9] }.
How do I use this cell array as input argument for a function?
function B = merge(C)
for i = 1:3
for j = 1:3
if i<j
B = [C{i};C{j}]
end
end
end
Thanks!
  2 件のコメント
Stephen23
Stephen23 2019 年 10 月 7 日
編集済み: Stephen23 2019 年 10 月 7 日
"How do I use this cell array as input argument for a function?"
Just pass it as an argument:
C_in = {....};
B_out = merge(C_in)
Note that your code overwrites B each time that line is evaluated, thus making both loops superfluous and your code simply equivalent to B = [C{2};C{3}]
muhammad muda
muhammad muda 2019 年 10 月 7 日
But I tried to run this program and it says "Not enough input arguments".
How can I solve this?

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

採用された回答

meghannmarie
meghannmarie 2019 年 10 月 7 日
編集済み: meghannmarie 2019 年 10 月 7 日
This works for me. Maybe matlab has another merge function? Type this:
which merge
Make sure the path its giving you points at YOUR merge.m file and not a path to a MATLAB toolbox. If it is pointing at a different one, change the name of your function and file to merge2 or something.
  1 件のコメント
muhammad muda
muhammad muda 2019 年 10 月 7 日
Yes it works now, thanks..

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMatrices and Arrays についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by