Want to apply two different functions on different elements of a vector.
2 ビュー (過去 30 日間)
古いコメントを表示
Vinay Killamsetty
2019 年 5 月 9 日
コメント済み: Vinay Killamsetty
2019 年 5 月 9 日
How can we operate two seperate functions on elements of a row vector: one function should be operated on even position elements and other function should be operated on odd position elements by using array function or by any other means.
Finally the outcomes of those operations should be combined as a another row vector
2 件のコメント
Erivelton Gualter
2019 年 5 月 9 日
Hi dear,
Could you clarify this problem better? WOuld be help full to share some code as well.
採用された回答
Alex Mcaulley
2019 年 5 月 9 日
編集済み: Alex Mcaulley
2019 年 5 月 9 日
a = 1;
b = 5;
odd = @(w) a*w+b*w^2;
even = @(w) a*w^2+b*w;
curr_w = rand(1,5);
aa = arrayfun(odd,curr_w(1:2:numel(curr_w)));
bb = arrayfun(even,curr_w(2:2:numel(curr_w)));
res(1:2:numel(curr_w)) = aa;
res(2:2:numel(curr_w)) = bb;
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Matrices and Arrays についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!