R
R
Raheb Wataniar2017-11-14 20:56:39
Arrays
Raheb Wataniar, 2017-11-14 20:56:39

Why don't array elements add up?

there are two arrays PP1 and PP2 , they are initialized in the loop, one of the values ​​in the loop changes with each iteration - PP1.
Why in the output (PP array) , the sum of these two arrays (PP1 and PP2) is only PP2.
PS Arrays are declared before the loop and initialized as empty, both. Array PP1 takes 16 different values ​​with each iteration, PP2 takes the same value (const) with each iteration.
I made it so that I would take 1 element from the first array and sum it with 1 element of the second array.
PP(i)=PP1(i)+PP2(i)
Code Listing:

clc;
clear all;
r= 150;
a= 0.8;
b= 1.5;
N= 4;
n= 15;
re= 150+15;
p = 10^4;
f= 10^9;
R= 8500;
c= 3.8*10^8;
n0= 5:1:20;

C= (factorial(2*N-1))/((factorial(N))*(factorial(N-1)));

t= (re*10^3*a/2*c)*((re/R)+2*a);

PP=[];
PP1=[];
PP2=[];
for i=1:1:length(n0)
    PP1(i)= (C/(2*n0(i))^N);
    PP2(i)= 10*C*((t*b/6)*(1+log(1+(1/2*pi*t*b^2)))^N);  
    PP(i)=PP1(i)+PP2(i); 
end

plot (PP);
grid on;
xlabel('сигнал/шум, n0') 
ylabel('Полная Вероятность Ошибки, Р(ош.N)')

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Roman Mirilaczvili, 2017-11-15
@2ord

C, t - constants
n0, PP1 - vectors
PP2 - a constant that can be taken out of the loop.
Instead of a for loop in Matlab, it is customary to perform vector operations in one line.
In order to divide/raise each member of the vector, you need to add a dot before the operation: What then does PP = PP1 + PP2 mean, where PP2 is a constant? Unclear.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question