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 Kommentare

Chandrasekhar
Chandrasekhar am 11 Mär. 2014
t cannot take negative values as it is acting as index
Marta Salas
Marta Salas am 11 Mär. 2014
Bearbeitet: Marta Salas am 11 Mär. 2014
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
sharif am 11 Mär. 2014
It is an approximate model of flat edge in communication systems where I must have 10 different lines running from n=1 to n=100

Melden Sie sich an, um zu kommentieren.

 Akzeptierte Antwort

Chris C
Chris C am 11 Mär. 2014

0 Stimmen

I'm still not reall clear on what you're looking for, but try this version of Marta's code...
c1=3.29;
c2=9.90;
c3=0.77;
c4=0.20;
t = linspace(0,-1,10); %definition of t vector
n = linspace(1,100);
Ln=zeros(length(t),length(n));
for i=1:length(t)
for j = 1:length(n);
Ln(i,j)= -(c1+c2*log(n(j))*log(-t(i)))-(c3+c4*log(n(j)));
end
semilogx(n,Ln(i,:))
hold on
end

2 Kommentare

sharif
sharif am 11 Mär. 2014
yes I think this method is correct, although the graph is wrong, I have to check why it's wrong, thanks
Chris C
Chris C am 12 Mär. 2014
Bearbeitet: Chris C am 12 Mär. 2014
What's wrong about the graph? If it's because the lines are all blue all you have to do is populate the data first within the for loops and then graph it all at once after the loops instead of plotting a line after each iteration around i.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (2)

dpb
dpb am 11 Mär. 2014

0 Stimmen

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
Marta Salas am 11 Mär. 2014

0 Stimmen

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 Kommentare

sharif
sharif am 11 Mär. 2014
I wanted to plot for each n all values of t, i.e. when n=1, t=-0.1,-0.2,-0.3 till -1.0, couldn't achieve it with this solution :(
dpb
dpb am 11 Mär. 2014
Bearbeitet: dpb am 11 Mär. 2014
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
sharif am 11 Mär. 2014
I will check it now thanks
dpb
dpb am 11 Mär. 2014
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
sharif am 11 Mär. 2014
This is resulting 100 lines I want only 10 lines 10 lines containing the 100 values, anyway thanks for trying to help.
Marta Salas
Marta Salas am 11 Mär. 2014
Sorry, I don't really understand what you mean about 10 lines.
dpb
dpb am 11 Mär. 2014
Well, read and do a little thinking on your own...fix the upper limit on the for loop to be 1:length(n)

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Entering Commands finden Sie in Hilfe-Center und File Exchange

Tags

Noch keine Tags eingegeben.

Gefragt:

am 11 Mär. 2014

Bearbeitet:

am 12 Mär. 2014

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by