All functions in a script must be closed with an 'end'.

76 次查看(过去 30 天)
hi i have got problem when running program, this message error :
Error: File: data_field_gn_80M.m Line: 147 Column: 4
All functions in a script must be closed with an 'end'.
the script such as
g%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%Data Field Generator for 80MHz Bandwidth %%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function [DATA_Field, Mapout, ILout, PAPR] = data_field_gn_80M(NTx, PSDU_field, Service_field, TXVECTOR, Scr_init, Q, FreqP, VarP)
%%%%%%%%%%%%%%%%%%%%%
%%%%%Parameter %%%%%
%%%%%%%%%%%%%%%%%%%%%
N_fft = 256;
L_SParseout = VarP.Ncbpss*VarP.Nsym ;
%%%Interleaving pattern generation %%%
%%%Revised by Wahyul, July 31th 2008 %%%
%%%faster process %%%
if TXVECTOR.LDPC_CODING == 0
% ILpattern = interleaving_pattern_gn(TXVECTOR.FORMAT, TXVECTOR.CW, TXVECTOR.CH_OFFSET, VarP.Nbpsc, VarP.Ncbpss, VarP.Nss) ;
ILpattern = interleaving_pattern_gn(1, TXVECTOR.CW, TXVECTOR.CH_OFFSET, VarP.Nbpsc, VarP.Ncbpss, VarP.Nss) ;
end
%%%Pilot generation %%%
% [Pilot_f, Pilot_t] = pilot_gn(VarP.Nsts, TXVECTOR.FORMAT, TXVECTOR.CW, TXVECTOR.CH_OFFSET) ;
[Pilot_f, Pilot_t] = pilot_gn(VarP.Nsts, 1, TXVECTOR.CW, TXVECTOR.CH_OFFSET) ;
%%%PSDU %%%
%%%Revised 070909
%%%if using LDPC-encoding, no tail bits and padding bits are applied
if TXVECTOR.LDPC_CODING == 0
Tail_bit = zeros(1, VarP.Ntail) ;
Pad_bit = zeros(1, VarP.Npad) ;
% Data_field = [Service_field PSDU_field Tail_bit Pad_bit] ;
Data_field = [Service_field PSDU_field Tail_bit Pad_bit] ;
else
Data_field = [Service_field PSDU_field];
end
%%%revision end
%%%Scrambler %%%
Scrout = scrambler(Data_field, Scr_init) ;
%%%Revised 070909
%%%same fashion above
if TXVECTOR.LDPC_CODING == 0
Scrout(VarP.Nbit+17:VarP.Nbit+16+VarP.Ntail) = zeros(1,VarP.Ntail) ; % Substitution of tail bit
end
%%%Encoder parser %%%
%%%Revised by Wahyul June 18th 2008
%%%When we BCC encoding is used, scrambled data is divided to Nes.
%%%When we LDPC encoding is used, scrambled data is not divided.
%%%Ref. Draft2 pp 235 (i).
switch TXVECTOR.LDPC_CODING
case 0
EParseout = encoder_parser(Scrout, VarP.Nes) ;
case 1
EParseout = Scrout;
end
%%%Revision end
%%%FEC encoder %%%
%%%Revised by Wahyul June 18th 2008
%%%Spatial Stream Parser %%%
%%%Revised by Wahyul August 4th 2008
%%%When we LDPC encoding is used, The Nes=1.
%%%Ref. Draft2 pp 235 (i).
switch TXVECTOR.LDPC_CODING
case 0
%%%Convolutional encoder %%%
for nes = 1 : VarP.Nes
Convout(nes,:) = conv_encoder(EParseout(nes,:)) ;
%%%Puncturer %%%
FECencout(nes,:) = puncurer(Convout(nes,:), VarP.Crate) ;
end
% Spatial stream parser, depend on number of FEC encoder (Nes)
[SParseout] = spatial_stream_parser(FECencout, VarP.Nbpsc, VarP.Nss, VarP.Nes) ;
case 1
%%%LDPC encoder %%%
[FECencout] = LDPCEncProc(EParseout, VarP.Crate, TXVECTOR.LENGTH, VarP.Ncbps, TXVECTOR.STBC);
% Spatial stream parser, Nes=1.
[SParseout] = spatial_stream_parser(FECencout, VarP.Nbpsc, VarP.Nss, 1) ;
end
%%%Revision end
% [SParseout] = spatial_stream_parser(FECencout, VarP.Nbpsc, VarP.Nss, VarP.Nes) ;
%%%Interleaver %%%
%%%Revised by Wahyul June 19th 2008
%%%When we LDPC encoding is used, No Interleaver is needed.
switch TXVECTOR.LDPC_CODING
case 0
for iss = 1 : VarP.Nss
ILout(iss,1:L_SParseout(iss)) = freq_interleaver(SParseout(iss,1:L_SParseout(iss)), ILpattern(iss,1:VarP.Ncbpss(iss)), VarP.Ncbpss(iss), VarP.Nsym) ;
end
case 1
ILout = SParseout;
end
%%%QAM mapper %%%
for iss = 1 : VarP.Nss
Mapout(iss,:) = mapper(ILout(iss,1:L_SParseout(iss)), VarP.Nbpsc(iss)) ;
end
%%%STBC encoder %%%
switch TXVECTOR.STBC
case 0
STBCencout = Mapout ;
otherwise
STBCencout = stbc_encoder(Mapout, VarP.Nss, VarP.Nsts, FreqP.Nsd, VarP.Nsym) ;
end
%%%Pilot inserter %%%
for nsts = 1 : VarP.Nsts
% PIout(nsts,:) = pilot_inserter(STBCencout(nsts,:), Pilot_f(nsts,:), Pilot_t, VarP.Nsym, TXVECTOR.FORMAT, TXVECTOR.CW, TXVECTOR.CH_OFFSET, 'data', FreqP) ;
PIout(nsts,:) = pilot_inserter(STBCencout(nsts,:), Pilot_f(nsts,:), Pilot_t, VarP.Nsym, 1, TXVECTOR.CW, TXVECTOR.CH_OFFSET, 'data', FreqP) ;
end
%%%Duplicator %%%
for nsts = 1 : VarP.Nsts
Dupliout(nsts,:) = duplicator_80M(PIout(nsts,:), 2, TXVECTOR.CH_OFFSET, VarP.Nsym) ;
end
%%%Spatial mapper %%%
SMapout = spatial_mapper(Dupliout, Q, NTx, VarP.Nsym, FreqP) ;
%%%Serial to parallel conversion %%%
for ntx = 1 : NTx
for sym = 1 : VarP.Nsym
SPout(ntx,:,sym) = SMapout(ntx,1+(sym-1)*256:sym*256) ;
end
end
%%%IFFT %%%
for ntx = 1 : NTx
IFFTout(ntx,1:256,1:VarP.Nsym) = ifft_80M(SPout(ntx,:,:), 256/sqrt(FreqP.Nst), VarP.Nsym) ;
end
%%%No Cyclic shift insertion in time domain %%%
for ntx = 1 : NTx
Tcs=[0 0 0 0];
CSIout(ntx,1:256,1:VarP.Nsym) = cs_inserter_80M(IFFTout(ntx,:,:), Tcs(ntx), VarP.Nsym) ;
end
%%%Guard interval inserter %%%
for ntx = 1 : NTx
GIIout(ntx,1:VarP.L_OFDM+3,1:VarP.Nsym) = gi_inserter_80M(CSIout(ntx,:,:), [-VarP.L_GI:256+3-1], VarP.Nsym) ;
end
%%%Time domain window shaper %%%
for ntx = 1 : NTx
Windowout(ntx,:) = time_window_shaper_80M(GIIout(ntx,:,:), VarP.Nsym, VarP.L_OFDM) ;
end
DATA_Field = Windowout ;
%%%PAPR calculation %%%
for ntx = 1 : NTx
PAPR(ntx,1:VarP.Nsym) = papr_40M(IFFTout(ntx,:,:), VarP.Nsym);
end
  2 个评论
Rik
Rik 2017-12-14
Apparently you have not matched all function calls with an end.
Take a look at your code in this question. Can you read it? If you want more help than this obvious solution, you will have to click edit, select your code and click the {}Code button.
Adam
Adam 2017-12-14
The error message gives all the clues you need, as they often do. It tells you you have a script, yet you declare a function at (near) the top, so that should immediately tell you that something is in front of your function definition that shouldn't be there.
Stephen's answer points out what this is, my point here is to encourage you to interpret the error message in a logical manner that will lead you to the solution.

请先登录,再进行评论。

回答(2 个)

Stephen23
Stephen23 2017-12-14
You need to remove the g:
g%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

Walter Roberson
Walter Roberson 2017-12-14
MATLAB supports three kinds of .m files:
  1. .m files for which the first non-comment is function, which are used to define functions
  2. .m files for which the first non-comment is classdef, which are used to define object oriented classes
  3. all other .m files, which are called scripts: these start with some executable code
Until a couple of releases ago, it was not permitted for "scripts" (.m that start with executable code) to define functions at all. I can tell from the error message that you are using a release that does support defining functions inside a script. However, there is a restriction on functions defined inside a script: it is required that each function defined there have an end statement matching the function statement. Your script does not have that end matching the function statement.
There is a further restriction on functions defined inside a script file: the name of the defined function must not match the name of the script file. In the case of the code you posted, the name of the function does match the name of the script, so even if you added the end statement at the end, you would still have problems.
What we have to suspect is that you accidentally put text at the top of your existing function file. For example the 'g' that Stephen points out.

类别

Help CenterFile Exchange 中查找有关 Call MATLAB from C++ 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by