0

I'm trying to store values in array xx and for each new loop iteration (i) I want the values divided by (j) to get stored in a new column (k).

My problem is that the (j) don't change for each new loop iteration and I get the same values for the entire array.

Any one knows how to solve this?

I want the variable 1/j in the first column to be j=0.01 and for the second column j=0.02 etc.

  for i= 1:1:61
      for k=1:1:8
          for j=0.01:0.01:0.08'
              xx(i,k) = nthroot(Q(i)/((1/j)*B*(S0^(1/2))),5/3);
          end  
      end    
  end

result

xx =

0.7841    0.7841    0.7841    0.7841    0.7841    0.7841    0.7841    0.7841
0.7841    0.7841    0.7841    0.7841    0.7841    0.7841    0.7841    0.7841
0.7841    0.7841    0.7841    0.7841    0.7841    0.7841    0.7841    0.7841
0.7841    0.7841    0.7841    0.7841    0.7841    0.7841    0.7841    0.7841
0.7841    0.7841    0.7841    0.7841    0.7841    0.7841    0.7841    0.7841
0.7841    0.7841    0.7841    0.7841    0.7841    0.7841    0.7841    0.7841
0.7841    0.7841    0.7841    0.7841    0.7841    0.7841    0.7841    0.7841
0.8302    0.8302    0.8302    0.8302    0.8302    0.8302    0.8302    0.8302
0.8747    0.8747    0.8747    0.8747    0.8747    0.8747    0.8747    0.8747
0.9177    0.9177    0.9177    0.9177    0.9177    0.9177    0.9177    0.9177
0.9594    0.9594    0.9594    0.9594    0.9594    0.9594    0.9594    0.9594
1.0000    1.0000    ... 

Cheers!

1 Answer 1

1

You are using wrongly the loops, you don't need the third loop. Just create the vector j at beginning and use the value j(k) in your computation.

j=0.01:0.01:0.08;
for i= 1:1:61
    for k=1:1:8
        xx(i,k) = nthroot(Q(i)/((1/j(k))*B*(S0^(1/2))),5/3);  
    end    
end
Sign up to request clarification or add additional context in comments.

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.