changing a loop to a function

for x = 1:100
for y = 1:61
b = abs(bsxfun(@minus,q{x},kevin))
s{x,y} = b;
end
end
How do I incorporate the above code as function?
the variables kevin and q are already loaded on the workspace.
thanks

 採用された回答

Azzi Abdelmalek
Azzi Abdelmalek 2014 年 12 月 21 日
編集済み: Azzi Abdelmalek 2014 年 12 月 21 日

0 投票

function s=yourfunction(q,kevin)
for x = 1:100
for y = 1:61
b = abs(bsxfun(@minus,q{x},kevin))
s{x,y} = b;
end
end
save this file as yourfunction.m
To call this function
q= % assign value to q
kevin= % assign value to kevin
s=yourfunction(q,kevin)

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeLoops and Conditional Statements についてさらに検索

タグ

質問済み:

AA
2014 年 12 月 21 日

編集済み:

2014 年 12 月 21 日

Community Treasure Hunt

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

Start Hunting!

Translated by