How do I pass extra known parameters to arrayfun?

7 ビュー (過去 30 日間)
cui,xingxing
cui,xingxing 2021 年 8 月 6 日
編集済み: cui,xingxing 2021 年 8 月 6 日
For example, if I want to find the position in the corresponding array b from each element of array a, how should I write the code?
a = [1,2,3];
b = [2,1,1,3,1,2];
idx = arrayfun(@(x,b)find(x==b),a,b)
Error using arrayfun
All of the input arguments must be of the same size and shape.
Previous inputs had size 3 in dimension 2. Input #3 has size 6
The desired idx outcome is:{[2,3,5],[1,6],[4]}

採用された回答

cui,xingxing
cui,xingxing 2021 年 8 月 6 日
編集済み: cui,xingxing 2021 年 8 月 6 日
I get the answer:
a = [1,2,3];
b = [2,1,1,3,1,2];
idx = arrayfun(@(x)find(x==b),a,'UniformOutput',false)
idx = 1×3 cell array
{[2 3 5]} {[1 6]} {[4]}

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeGraphics Object Programming についてさらに検索

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by