How to assign an element of a column array to a variable?
Afficher commentaires plus anciens
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 commentaires
David Young
le 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
le 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
le 18 Sep 2014
Adam
le 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.
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Introduction to Installation and Licensing dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!