How to assign an element of a column array to a variable?
Show older comments
Sorry if this might seem silly, but I am not able to get this: I have :
d0=rand(Nn,1);
M=2+2*rand(Nn,1);
NN=2+2*rand(Nn,1);
RR=0.35+0.25*rand(Nn,1);
d=zeros(Nn,1);
ni=zeros(Nn,1);
for i=1:Nn
D0=d0(i,1);
r=RR(i,1);
n=NN(i,1);
m=M(i,1);
D=1-power(power(1-D0,n+1)-((N-N0)/Nc).*(n+1).*power((1-r/R1),m),1./(n+1));
d(i,1)=D;
end
gives:
Subscript indices must either be real positive integers or logicals.
Error in constant_loading_1 (line 3) D0=d0(i,1);
5 Comments
David Young
on 18 Sep 2014
I copied your code and ran it and I don't get the error - is what you're running exactly what you've shown here?
Adam
on 18 Sep 2014
Looks fine to me though is that exactly the code that gave the error? It is pointing to a line3, but the code it shows as causing the problem is not the 3rd line of that code.
Sri
on 18 Sep 2014
Adam
on 18 Sep 2014
You are assigning new random data to each of them. If you want the same data just define the others in terms of the first one you assign.
You can setup random seed I think to ensure each call to rand starts from the same seed and would thus give the same sequence for a given length, but for your case that seems overboard and the above method would be far easier.
Accepted Answer
More Answers (0)
Categories
Find more on Introduction to Installation and Licensing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!