From: y on
my code is
function [ Z_TOT,Z_TOT_INTR,rate_match_output,rate_match_output1,F] = turbo1( SEG_BLOCKS )

global c_min
global c_max
global k_min
global k_max
global block_size
global filler_bits
global F1
global F2
persistent rate1
persistent rate2
%% matrix of k from aseel code
load turbo_intr
%% calculation of f2 matrix
load turbo_intr_2
%% matrix of f1
load turbo_intr_1

%i am trying to seperate blocks from SEG_BLOCKS
MIN_BLOCKS=SEG_BLOCKS(1,(c_max*block_size(1)+1):end);

for t=1:c_min
N1=block_size(c_max+1);
c1=MIN_BLOCKS(1,((t-1)*N1+1:(t*N1)));
x_k1=c1;
%% encode the message
m1=0; % initial content of memory register equal zero
m2=0;
p=0;
m3=0;
z1=zeros(1,N1);
for i=1:N1 % For N input bits
b = xor(c1(i),m2);
d = xor(b,m1);
z1(i)=xor(d,p);
m2=xor(m3,p);
p=m3;
m3=m1; % Content of memory register m1 shifting to m3
m1=b;
end
z1_tot(1,((t-1)*N1+1:(t*N1)))=z1; % the total output after encoder

%% choose the value of f1 & f2
k1 = k_min;
G=find(k1==turbo_intr);
f1_value =turbo_intr_1(G);
f2_value=turbo_intr_2(G);

%% matrix after interleaver
c_intr=zeros(1,N1);
x=zeros(1,N1);

for s=1:N1
x(s)=mod((f1_value*s + f2_value*(s^2)),k1 );
if x(s)==0
x(s)=s;
end
c_intr(s)=c1(x(s));
end

%% 2_nd encoder after interleaver
m11=0; % initial content of memory register equal zero
m22=0;
p1=0;
m33=0;
N1 = length(c1) ; % N inputs to the ecoder
z_intr1 = zeros(1,N1); % output of encoder
z_tot_intr1=zeros(1,N1);
for i=1:N1 % For N input bits
b1 = xor(c1(i),m22);
d1 = xor(b1,m1);
z_intr1(i)=xor(d1,p1); % output from 2_nd encoder after interleaver
m22=xor(m33,p1);
p1=m33;
m33=m11; % Content of memory register m11 shifting to m33
m11=b1;
end
z_tot_intr1(1,((t-1)*N1+1:(t*N1)))=z_intr1 ; % the total output after interleaver & encoder for seg max

T=rate(x_k1,z1,z_intr1);
rate1=zeros(1,length(T));
rate1(t,:)=T;
rate_match_output=rate1;
F1=Code_block_concatenation(T);
end
if c_max~=0
MAX_BLOCKS=SEG_BLOCKS(1:c_max*block_size(1));

MAX_BLOCKS(1,(1:filler_bits))=2;
for g=1:c_max
N=block_size(1);
c=MAX_BLOCKS(1,(g-1)*N+1:(g*N));
x_k=c;
%% encode the message
m1=0; % initial content of memory register equal zero
m2=0;
p=0;
m3=0;
z = zeros(1,N); % output of encoder for one row
for i=1:N % For N input bits
b = xor(c(i),m2);
d = xor(b,m1);
z(i)=xor(d,p);
m2=xor(m3,p);
p=m3;
m3=m1; % Content of memory register m1 shifting to m3
m1=b;
end
z_tot(1,((g-1)*N+1:(g*N)))=z ;
%% choose the value of f1 & f2
k1 = k_max;
G=find(k1==turbo_intr);
f1_value =turbo_intr_1(G);
f2_value=turbo_intr_2(G);

%% matrix after interleaver
c_intr=zeros(1,N); % matrix after interleaver
x=zeros(1,N);
for s=1:N
x(s)=mod((f1_value*s + f2_value*(s^2)),k1 );
if x(s)==0
x(s)=s;
end
c_intr(s)=c(x(s));
end

%% 2_nd encoder after interleaver
m11=0; % initial content of memory register equal zero
m22=0;
p1=0;
m33=0;
N = length(c) ; % N inputs to the ecoder
z_intr = zeros(1,N); % output of encoder for one row
z_tot_intr=zeros(1,N);
for i=1:N % For N input bits
b1 = xor(c(i),m22);
d1 = xor(b1,m1);
z_intr(i)=xor(d1,p1); % output from 2_nd encoder after interleaver
m22=xor(m33,p1);
p1=m33;
m33=m11; % Content of memory register m11 shifting to m33
m11=b1;
end
z_tot_intr(1,((g-1)*N+1:(g*N)))=z_intr ; % the total output after interleaver & encoder for seg min

U=rate(x_k,z,z_intr);
rate2=zeros(1,length(U));
rate2(g,:)=U;
rate_match_output1=rate2;
F2=Code_block_concatenation(U);
%concatanation function

end
else
z_tot=[];
z_tot_intr=[];
rate_output=[];
F2=[];
end
Z_TOT=[z_tot z1_tot];
Z_TOT_INTR=[z_tot_intr z_tot_intr1];
F=[F1 F2];
toc
end


and there is error
Error in ==> turbo1 at 3
global c_min

??? Output argument "rate_match_output1" (and
maybe others) not assigned during call to
"C:\Users\USER\Documents\MATLAB\new_work\turbo1.m>turbo1".
?!!!!!!!!!!!!
how can i solve it ?!!!!!
From: David Young on
> my code is
> function [ Z_TOT,Z_TOT_INTR,rate_match_output,rate_match_output1,F] = turbo1( SEG_BLOCKS )
....
> end
>
>
> and there is error
> Error in ==> turbo1 at 3
> global c_min
>
> ??? Output argument "rate_match_output1" (and
> maybe others) not assigned during call to
> "C:\Users\USER\Documents\MATLAB\new_work\turbo1.m>turbo1".
> ?!!!!!!!!!!!!
> how can i solve it ?!!!!!

Try assigning a value to rate_match_output1 ?!!!!! - even in the case that c_max is zero.

Your code is hard to read because it's not indented properly, but at a quick look I think the assignment to this variable only occurs when c_max is non-zero. As an output, it needs to be given a value no matter what branches the computation takes.

More generally, it would be a good idea to avoid global variables, and to split this function up into smaller, simpler functions that you can debug independently.