samedi 5 mars 2016

Adding row to matrix in if statement MATLAB

I have a code that should do exactly this:

A = [2;3;4;5;6;7];
b = 2;
B(10).b = zeros(6,1);

for i = 1:10
    C = A;
    B(i).b = C.*(b^i);
    if i>1
        if B(i).b(1,1)-B(i-1).b(1,1)>50
            C(7) = b;
        end
    end
end

The problem is that in every iteration C matrix is replaced with the values in matrix A. This is simplified version of my code, but the essence is here, and the code should do exactly this, at some point if a criteria is met, add another row to matrix C and continue executing the code with that row in matrix C. Is it possible to do that? I'd appreciate ideas very much. Thank you.

Aucun commentaire:

Enregistrer un commentaire