How to display results for looping
4 views (last 30 days)
Show older comments
helle everyone.. I would like to ask a question regarding to my programming. I have this code as below. I want to display all the result for each iteration. which part do I need to put the syntax so that it can store the result from 1st iteration till 5th and display all the result (x1_new,x2_new,y_new) when the loop is done..
clc clear a=5; alpha=0.2
x1=ceil(rand(a,1)*10); x2=ceil(rand(a,1)*10); y=x1+x2 data=[x1 x2 y]
for n=1:5 for i=1:5 if y(n)<y(i)
r=(data(n,1)-data(i,1))^2+(data(n,2)-data(i,2))^2
p=sqrt(r)
x1_new=ceil(data(i,1)+exp(-p^2)*(data(i,1)-data(i,1))+alpha.*(rand-0.5))
x2_new=ceil(data(i,2)+exp(-p^2)*(data(i,2)-data(i,2))+alpha.*(rand-0.5))
y_new=x1_new(i)+x2_new
else
x1_new=data(i,1)
x2_new=data(i,2)
y_new=data(i,3)
end
end
end
end
tq for your help..
0 Comments
Answers (3)
per isakson
on 18 Jul 2013
The results need to be arrays, i.e.
x1_new(n,i)
x2_new(n,i)
y_new(n,i)
0 Comments
Image Analyst
on 18 Jul 2013
In the line
result(n,i)=[x1_new(n,i) x2_new(n,i) y_new(n,i)]
you're trying to stuff 3 elements into a single result element. You can't do that. You can put only 1 element into that element.
0 Comments
See Also
Categories
Find more on Logical 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!