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

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

You can omit the square brackets around the output of myFunction.
I do not understand the question. What mean "from range 1"? And what is the 2nd range of i? Could you give us a small example?
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!
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)

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

Asked:

on 29 Jul 2013

Community Treasure Hunt

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

Start Hunting!