How to limit operation range of bsxfun(@plus,a,b)

1 view (last 30 days)
Hi all, I would like to use bsxfun to add an element (from range 1) ONLY to the array resulting in the 2nd range of i. The code below results in addition of dp(5) to the hole array (i=1:1:10) what I dont want. Any proposals!? Thanks in advance!
for i=1:1:5
x(i)=i;
[dp(i)] = myfunction(x(i))
end
for i=6:1:10
x(i)=i;
[dp(i)] = myfunction(x(i))
dp_out=bsxfun(@plus,dp,dp(5))
end
end
  3 Comments
Horst Guenter
Horst Guenter on 30 Jul 2013
With "from range 1" I mean the output of myfunction for i=0:1:5. And "2nd range of i" is meant the output of myfunction for i=6:1:10. The crrent output is as below:
dp=[2 1 1 1 1 3 3 3 3 3]
I would like to get the following result:
dp=[2 1 1 1 1 5 5 5 5 5]
Thanks!
the cyclist
the cyclist on 30 Jul 2013
I am a little confused now, but I am 99% certain that you do not need bsxfun, and can use something simple like the answer I have entered below.

Sign in to comment.

Answers (1)

the cyclist
the cyclist on 29 Jul 2013
Is dp a vector, or some other shape?
Can you simply do
>> dp(5:10) = dp(5:10) + dp(5)
?

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!