0

I have created one loop inside another in matlab, and i want to create a matrix inside this second loop that gives the values of the two increments plus a parameter that is being calculated. I made the following code but the matrix is just saving the last values, so it is not a matrix is a vector:

for inclin=29:1:39
    for alfa=1:1:90
        Ii_perc=...
        Di_perc=...
        Gi_perc=...
        r=...
        matriz=[inclin alfa r]
    end
end

So, i want to have a matrix with the different combinations of inclin/alfa/r that the loop gives in each loop, i.e, something like this:

 matriz =[29  1  0.34
          29  2  0.32
          29  3  0.40
          ...........]

I really need some help to solve this problem.. Thanks!

2 Answers 2

1

If I correctly you understand I can offer this variation:

Matrix = zeros((39-29+1)*90,3);
count = 1;
for inclin=29:1:39
    for alfa=1:1:90
        r=rand();
        Matrix(count,:)=[inclin alfa r];
        count = count+1;
    end
end
Sign up to request clarification or add additional context in comments.

Comments

0

The problem is that

matriz=[inclin alfa r] 

is a vector. If you want to append an additional row every loop iteration, you need to index it like this:

matriz(i, :)=[inclin alfa r]

Using the colon in this way says to assign the right hand side of the equation to the ith row of matriz.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.