How to assign an element of a column array to a variable?
이전 댓글 표시
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
David Young
2014년 9월 18일
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
2014년 9월 18일
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
2014년 9월 18일
Adam
2014년 9월 18일
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.
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Introduction to Installation and Licensing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!