Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

column extraction in matlab

Asked by PK on 17 Oct 2012

can some one help in this my Fitness values are Fitness =

    0.0443
    0.0473
    0.0475
    0.0475
    0.0476
    0.0475
    0.0443
    0.0476
    0.0473
    0.0467 and these are fitness values of a 10x100 matrix each fitness value corresponds to a single row and the fitness values changes in every execution and for current execution the min value is at 1st position but for next execution it may change so that the minimum valued fitness row should be extracted and placed in a variable i tried it with for loop but not fetting result and it is as below
Fitness=calculateFitness(ObjVal);
indx=find(Fitness==min(Fitness));
row=Foods;
for indx=1;row=Foods(1,:);
    indx=2;row=Foods(2,:);
    indx=3;row=Foods(3,:);
    indx=4;row=Foods(4,:);
    indx=5;row=Foods(5,:);
    indx=6;row=Foods(6,:);
    indx=7;row=Foods(7,:);
    indx=8;row=Foods(8,:);
    indx=9;row=Foods(9,:);
    indx=10;row=Foods(10,:);
end
pbest=row;

0 Comments

PK

Products

No products are associated with this question.

1 Answer

Answer by Walter Roberson on 17 Oct 2012
Accepted answer

Something like

for indx = 1 : 10
  row = Foods(indx,:);
end

3 Comments

PK on 17 Oct 2012

but this is giving index value as 10 always

Walter Roberson on 17 Oct 2012

Ah, perhaps you just meant

row = Foods(indx,:);

You coded a "for" loop, and "for" loops have to do with iteration. If you want to test values and do different things for different values, use "switch"

PK on 17 Oct 2012

k fine and in the same program the command indx=find(Fitness==min(Fitness)); states that location of min fitness is to be stored in the variable called indx but its not happening so and in the command window if i reun the statement find(Fitness==min(Fitness)) it shows exact location but not showing exact location of min fitness all the time when i run the code y so that happens

Walter Roberson

Contact us