index must be a positive integer or logical.
이전 댓글 표시
c1=3.29;
c2=9.90;
c3=0.77;
c4=0.20;
Ln=zeros(1,length(t));
for n=1:1:100;
for t=0:-0.1:-1;
Ln(t)=-(c1+c2*log(n)*log(-t))-(c3+c4*log(n));
semilogx(n,Ln(t));
end
end
I really want t to count negative, what am I supposed to do??
댓글 수: 3
Chandrasekhar
2014년 3월 11일
t cannot take negative values as it is acting as index
Marta Salas
2014년 3월 11일
편집: Marta Salas
2014년 3월 11일
You're going to define an index that it's not related with t but with the size of t. However I don't understand what you are trying to plot there. Which is the result you are expecting from that code? what do you want to plot on semilogx?
sharif
2014년 3월 11일
채택된 답변
추가 답변 (2개)
dpb
2014년 3월 11일
0 개 추천
Keep the time as associated independent vector of same length as the solution vector but numbered from 1:N instead of trying to use it as an index.
Marta Salas
2014년 3월 11일
A solution is this:
c1=3.29;
c2=9.90;
c3=0.77;
c4=0.20;
Ln=zeros(1,length(t));
t= 0:-0.1:-1; %definition of t vector
for n=1:1:100;
for i=1:length(t);
Ln(i)= -(c1+c2*log(n)*log(-t(i)))-(c3+c4*log(n));
semilogx(n,Ln(i));
end
end
Take into account semilogx(n,Ln(i)) is plotting a point. is this the right solution?
댓글 수: 7
sharif
2014년 3월 11일
plot for each n all values of t...
t= 0:-0.1:-1; %definition of t vector
for n=1:100
LN=log(n);
Ln= -(c1+c2*LN.*log(-t))-(c3+c4*LN);
semilogx(t,Ln);
if n==1,hold on,end
end
You can also get rid of the loop on n entirely as well...
doc meshgrid % for example
sharif
2014년 3월 11일
dpb
2014년 3월 11일
BTW, log(0) --> -inf so you'll probably want to restrict t>0
I meant to point it out above but forgot to go back and do it after finished the other modifications...
sharif
2014년 3월 11일
Marta Salas
2014년 3월 11일
Sorry, I don't really understand what you mean about 10 lines.
dpb
2014년 3월 11일
Well, read and do a little thinking on your own...fix the upper limit on the for loop to be 1:length(n)
카테고리
도움말 센터 및 File Exchange에서 Entering Commands에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!