How to implement elitism in Matlab? For example, I run the program and after each run the value is stored in the say a variable and after all the runs, say, 6 starts, I have the afollowing
a = [7, 5, 4, 3, 6, 8];
how can I apply elitism ato the end of the content aasa = [7, 5, 4, 3, 3, 3];
That is, when I look through a, I replace the larger number with the smaller one that I come across. From example, after scanning through a, 5<7so I remain 5, 4<5so I hold 4, 3<4so I hold 3, 3<6so I replace 6on 3again 3< 8, so I substitute 8on 3until the end of abotha = [7, 5, 4, 3, 3, 3];
how to do it in matlab.
Attempt
I said:
if a(i)< a(i+1)
a(i+1) = a(i);
end
plot(a);
so that I can have a schedule that runs smoothly.
but I keep having the following error:
'Subscript indices must either be real positive integers or logicals.'
Any idea how I can do this right.
source
share