what is assignment error in the following code?

clc;
clear all;
Pa=9;
R=3;
beta=8;
N=4;
P0=0.3726;
q1= 1:1:10;
pout3=1-exp(-(((2^R)-1)/(P0))^(beta/2));
for j=1:length(q1)
k = floor((j*N)/Pa);
for jj = 1:N-k-1
P(j,jj)=0;
pout1(j,jj)=1-exp(-(((2^R)-1)/(P(j,jj)))^(beta/2));
end
for l = N-k+1:N
PP(j,l)=((N*j)-P0)/k;%ko;
pout2(j,l)=1-exp(-(((2^R)-1)/(PP(j,l)))^(beta/2));
end
end
for j=1:length(q1)
k = floor((j*N)/Pa);
outage_f(j)=((pout1(j,:)+sum(pout2(j,N-k+1:N))+ pout3)/N);
end
plot(q1,outage_f,'*y');
grid on;
xlabel('transmit power');
ylabel('outage probability');
while executing above code..... In an assignment A(I) = B, the number of elements in B and I must be the same.
Error in fig2 (line 28) outage_f(j)=((pout1(j,:)+sum(pout2(j,N-k+1:N))+ pout3)/N);
it showing above error........... how to correct it??

2 comentarios

José-Luis
José-Luis el 29 de En. de 2014
Editada: José-Luis el 29 de En. de 2014
Have you tried using the debugger? Set a breakpoint in line 28 and look at the offending matrices.
kanchanamala
kanchanamala el 29 de En. de 2014
yes ,i used debugger but showing error in the first iteration itself...... i dont know what error in it...

Iniciar sesión para comentar.

Respuestas (2)

Iain
Iain el 29 de En. de 2014

1 voto

Changing outage(j) to outage(j,:) or outage(:,j) will corect the error.
The problem is that you're adding a scalar to a vector and then trying to put the result in a space thats only big enough for a scalar.

9 comentarios

kanchanamala
kanchanamala el 29 de En. de 2014
when i used outage(j,:), it showing error as Attempted to access pout1(7,:); index out of bounds because size(pout1)=[6,3].
Error in fig2 (line 29) outage_f(j,:)=((pout1(j,:)+sum(pout2(j,N-k+1:N))+ pout3)/N);
Iain
Iain el 29 de En. de 2014
Ok, so the first error is corrected, now to deal with the second:
You're trying to use the seventh, eightth, nineth and tenth rows of pout1, when it has six. How would you like it to behave?
kanchanamala
kanchanamala el 29 de En. de 2014
actually we are trying to plot outage Vs power(q1) while running q1 from 1 to 10
kanchanamala
kanchanamala el 29 de En. de 2014
Editada: kanchanamala el 29 de En. de 2014
Actually this is our problem
If q1<Pa we have
Pi* = 0 , 1 i N-k-1
= P0', i=N-k
=(Nq1 - P0')/k , N-k+1 i N
Where q1 and k are given as follows
k =⌊(q1 * N)/Pa⌋
P0'= arg min(P belongs to p) F(P) + k*F[((N*q1)-P)/k],
with p= [0,Pb] union (N*q1/(k+1))
where N= total no.of blocks = 4
i= no.of.blocks within total block
Pb=7.2
Pa=9.3
q1=average transmit power which varies from 1 to 10
F(P)= 1-(exp(-((2^(R))-1)/P)^(beta/2))
R=3
beta=8
our problem is to write a matlab code for Pi*
We need to plot for average transmit power and outage prob {F(P)}.....For P0' we found the value as 0.3762
Iain
Iain el 29 de En. de 2014
In that case, your formulae are entirely wrong, or they're not quite entirely wrong but you've also got garbage data.
kanchanamala
kanchanamala el 29 de En. de 2014
actually this our theorem,we have to code it in matlab. what we have to done? pls help me sir am new to matlab you said formulae is wrong can you correct it......
Iain
Iain el 29 de En. de 2014
pout3 evaluates to 1. pout1 evaluates to 1. Your probability of outage would therefore be at least 200%, which is clearly wrong.
I don't understand what you are trying to do because I don't know the background of the problem.
kanchanamala
kanchanamala el 29 de En. de 2014
the above program is according to the theorem which i was posted before......
kanchanamala
kanchanamala el 30 de En. de 2014
pls reply us for this code........

Iniciar sesión para comentar.

Azzi Abdelmalek
Azzi Abdelmalek el 29 de En. de 2014
Editada: Azzi Abdelmalek el 29 de En. de 2014
% The expression outage_f(j)=(pout1(j,:)+sum(pout1(j,N-k+1:N))+ pout3)/N; becomes
outage_f(j,:)=(pout2(j,:)+sum(pout2(j,N-k+1:N))+ pout3)/N;
Because the size of pout1 is 6x3 and length(q1) is 10
%-----------------------------------------
clc;
clear
Pa=9;
R=3;
beta=8;
N=4;
P0=0.3726;
q1= 1:1:10;
pout3=1-exp(-(((2^R)-1)/(P0))^(beta/2));
for j=1:length(q1)
k = floor((j*N)/Pa);
for jj = 1:N-k-1
P(j,jj)=0;
pout1(j,jj)=1-exp(-(((2^R)-1)/(P(j,jj)))^(beta/2));
end
for l = N-k+1:N
PP(j,l)=((N*j)-P0)/k;%ko;
pout2(j,l)=1-exp(-(((2^R)-1)/(PP(j,l)))^(beta/2));
end
end
for j=1:length(q1)
k = floor((j*N)/Pa);
outage_f(j,:)=(pout2(j,:)+sum(pout2(j,N-k+1:N))+ pout3)/N;
end
plot(q1,outage_f,'*r');
grid on;
xlabel('transmit power');
ylabel('outage probability');

10 comentarios

kanchanamala
kanchanamala el 29 de En. de 2014
but we want to add pout1 also...
You have to decide what to put instead of q1, because the size of pout1 is 6x3 and the length of q1 is 10, unless you zeros to pout1, just before the for loop
pout1(end+1:end+3,:)=0
Actually this is our problem
If q1<Pa we have
Pi* = 0 , 1 i N-k-1
= P0', i=N-k
=(Nq1 - P0')/k , N-k+1 i N
Where q1 and k are given as follows
k =(q1 * N)/Pa
P0'= arg min(P belongs to p) F(P) + k*F[((N*q1)-P)/k],
with p= [0,Pb] union (N*q1/(k+1))
where N= total no.of blocks
i= no.of.blocks within total block
Pb=7.2
Pa=9.3
q1=average transmit power which varies from 1 to 10
F(P)= 1-(exp(-((2^(R))-1)/P)^(beta/2))
R=3
beta=8
our problem is to write a matlab code for Pi*
We need to plot for average transmit power and outage prob {F(P)}.....For P0' we found the value as 0.3762
kanchanamala
kanchanamala el 29 de En. de 2014
sir actually you said use pout1=(end+1:end+3,:)=0 before for loop...... which for loop???
Azzi Abdelmalek
Azzi Abdelmalek el 29 de En. de 2014
Editada: Azzi Abdelmalek el 29 de En. de 2014
No, it's pout1(end+1:end+4,:)=0
pout1(end+1:end+4,:)=0;
for j=1:length(q1)
k = floor((j*N)/Pa);
outage_f(j,:)=(pout1(j,:)+sum(pout2(j,N-k+1:N))+ pout3)/N;
end
kanchanamala
kanchanamala el 29 de En. de 2014
sir we execute it but we getting rid of errors
is it our program is correct according to the theorem....
kanchanamala
kanchanamala el 29 de En. de 2014
we didnt get the correct graph....
pls check our code whether it is correct or not according to the theorem
kanchanamala
kanchanamala el 30 de En. de 2014
pls reply us for this code..........
Azzi Abdelmalek
Azzi Abdelmalek el 30 de En. de 2014
What theorem you are talking about?
Actually this is our problem
If q1<Pa we have
Pi* = 0 , 1 i N-k-1
= P0', i=N-k
=(Nq1 - P0')/k , N-k+1 i N
Where q1 and k are given as follows
k =(q1 * N)/Pa
P0'= arg min(P belongs to p) F(P) + k*F[((N*q1)-P)/k],
with p= [0,Pb] union (N*q1/(k+1))
where N= total no.of blocks = 4
i= no.of.blocks within total block
Pb=7.2
Pa=9.3
q1=average transmit power which varies from 1 to 10
F(P)= 1-(exp(-((2^(R))-1)/P)^(beta/2))
R=3
beta=8
our problem is to write a matlab code for Pi*
We need to plot for average transmit power and outage prob {F(P)}.....For P0' we found the value as 0.3762

Iniciar sesión para comentar.

Etiquetas

Preguntada:

el 29 de En. de 2014

Comentada:

el 30 de En. de 2014

Community Treasure Hunt

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

Start Hunting!

Translated by