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개)
Iain
2014년 1월 29일
1 개 추천
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
kanchanamala
2014년 1월 29일
Iain
2014년 1월 29일
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
2014년 1월 29일
kanchanamala
2014년 1월 29일
편집: kanchanamala
2014년 1월 29일
Iain
2014년 1월 29일
In that case, your formulae are entirely wrong, or they're not quite entirely wrong but you've also got garbage data.
kanchanamala
2014년 1월 29일
Iain
2014년 1월 29일
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
2014년 1월 29일
kanchanamala
2014년 1월 30일
Azzi Abdelmalek
2014년 1월 29일
편집: Azzi Abdelmalek
2014년 1월 29일
% 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
kanchanamala
2014년 1월 29일
Azzi Abdelmalek
2014년 1월 29일
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
kanchanamala
2014년 1월 29일
kanchanamala
2014년 1월 29일
Azzi Abdelmalek
2014년 1월 29일
편집: Azzi Abdelmalek
2014년 1월 29일
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
2014년 1월 29일
kanchanamala
2014년 1월 29일
kanchanamala
2014년 1월 30일
Azzi Abdelmalek
2014년 1월 30일
What theorem you are talking about?
kanchanamala
2014년 1월 30일
카테고리
도움말 센터 및 File Exchange에서 Resampling Techniques에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!