# Want to apply two different functions on different elements of a vector.

1 Ansicht (letzte 30 Tage)
Vinay Killamsetty am 9 Mai 2019
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 KommentareKeine anzeigenKeine ausblenden
Erivelton Gualter am 9 Mai 2019
Hi dear,
Could you clarify this problem better? WOuld be help full to share some code as well.
Vinay Killamsetty am 9 Mai 2019
a=1
b=5
odd=@(w) a*w+b*w^2
even=@(w) a*w^2+b*w
curr_w=[some user defined 1*n vector];
I want to perform even function on even position elements in curr_w and odd function on odd position elements to get the output vector curr_w.
If you need any additional information please let me know

Melden Sie sich an, um zu kommentieren.

### Akzeptierte Antwort

Alex Mcaulley am 9 Mai 2019
Bearbeitet: Alex Mcaulley am 9 Mai 2019
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;
##### 1 Kommentar-1 ältere Kommentare anzeigen-1 ältere Kommentare ausblenden
Vinay Killamsetty am 9 Mai 2019
Thank you so much Mr. Alex Mcaulley

Melden Sie sich an, um zu kommentieren.

### Kategorien

Mehr zu Matrices and Arrays finden Sie in Help Center und File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by