Getting message while converting following matlab code to c? This structure does not have a field 'numResources'; new fields cannot be added when structure has been read or used.
16 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Ankur Soni
el 19 de Mzo. de 2018
Editada: Fangjun Jiang
el 19 de Sept. de 2018
function p= prmsPDSCH(chanBW, contReg, modType, varargin)
% Returns parameter structures for LTE PDSCH simulation.
%
% Assumes a FDD, normal cyclic prefix, full-bandwidth, single-user
% SISO or SIMO downlink transmission.
%%PDSCH parameters
switch chanBW
case 1 % 1.4 MHz
BW = 1.4e6; N = 128; cpLen0 = 10; cpLenR = 9;
Nrb = 6; chanSRate = 1.92e6;
case 2 % 3 MHz
BW = 3e6; N = 256; cpLen0 = 20; cpLenR = 18;
Nrb = 15; chanSRate = 3.84e6;
case 3 % 5 MHz
BW = 5e6; N = 512; cpLen0 = 40; cpLenR = 36;
Nrb = 25; chanSRate = 7.68e6;
case 4 % 10 MHz
BW = 10e6; N = 1024; cpLen0 = 80; cpLenR = 72;
Nrb = 50; chanSRate = 15.36e6;
case 5 % 15 MHz
BW = 15e6; N = 1536; cpLen0 = 120; cpLenR = 108;
Nrb = 75; chanSRate = 23.04e6;
case 6 % 20 MHz
BW = 20e6; N = 2048; cpLen0 = 160; cpLenR = 144;
Nrb = 100; chanSRate = 30.72e6;
end
p.BW = BW; % Channel bandwidth
p.N = N; % NFFT
p.cpLen0 = cpLen0; % Cyclic prefix length for 1st symbol
p.cpLenR = cpLenR; % Cyclic prefix length for remaining
p.Nrb = Nrb; % Number of resource blocks
p.chanSRate = chanSRate; % Channel sampling rate
p.contReg = contReg;
if nargin > 3
numTx=varargin{4};
else
numTx=1;
end
if nargin > 4
numRx=varargin{5};
else
numRx=1;
end
p.numTx = numTx;
p.numRx = numRx;
p.numLayers = 1;
p.numCodeWords = 1;
% For Normal cyclic prefix, FDD mode
p.deltaF = 15e3; % subcarrier spacing
p.Nrb_sc = 12; % no. of subcarriers per resource block
p.Ndl_symb = 7; % no. of OFDM symbols in a slot
% Actual PDSCH bits calculation - accounting for PDCCH, PBCH, PSS, SSS
numResources = (p.Nrb*p.Nrb_sc)*(p.Ndl_symb*2);
numCSRRE = 2*2*2 * p.Nrb; % CSR, RE per OFDMsym/slot/subframe per RB
numContRE = (10 + 12*(p.contReg-1))*p.Nrb;
numBCHRE = 60+72+72+72; % removing the CSR present in 1st symbol
numSSSRE=72;
numPSSRE=72;
numDataRE=zeros(3,1);
% Account for BCH, PSS, SSS and PDCCH for subframe 0
numDataRE(1)=numResources-numCSRRE-numContRE-numSSSRE-numPSSRE-numBCHRE;
% Account for PSS, SSS and PDCCH for subframe 5
numDataRE(2)=numResources-numCSRRE-numContRE-numSSSRE - numPSSRE;
% Account for PDCCH only in all other subframes
numDataRE(3)=numResources-numCSRRE-numContRE;
% Maximum data resources - with no extra overheads (only CSR + data)
p.numResources=numResources;
p.numCSRResources = numCSRRE;
p.numContRE = numContRE;
p.numBCHRE = numBCHRE;
p.numSSSRE=numSSSRE;
p.numPSSRE=numPSSRE;
p.numDataRE=numDataRE;
p.numDataResources = p.numResources - p.numCSRResources;
% Modulation types , bits per symbol, number of layers per codeword
Qm = 2 * modType;
p.Qm = Qm;
p.numLayPerCW = p.numLayers/p.numCodeWords;
% Maximum data bits - with no extra overheads (only CSR + data)
p.numDataBits = p.numDataResources*Qm*p.numLayPerCW;
numPDSCHBits =numDataRE*Qm*p.numLayPerCW;
p.numPDSCHBits = numPDSCHBits;
p.maxG = max(numPDSCHBits);
end
0 comentarios
Respuesta aceptada
Fangjun Jiang
el 19 de Mzo. de 2018
Editada: Fangjun Jiang
el 19 de Mzo. de 2018
You are creating the structure p, adding its fields on-the-go. For example, fields "numTx", "numRx" and "numLayers" etc. are created. Then, the p structure is used in line "numResources = (p.Nrb*p.Nrb_sc)*(p.Ndl_symb*2)". Then more fields such as "numResources" are added.
According to the error message, this is not allowed. The code generation needs to know all the field names at the beginning, or at least, all the field names before the structure started being used.
You should create all those field names at the beginning of the code. Assign zero first and over-write it later. That should allow you to avoid this error message.
2 comentarios
Bhavanithya Thiraviaraja
el 19 de Sept. de 2018
I also faced the same problem when using inside a MATLAB function of a Simulink Model. My problem is I do not know the size of the value that is added to a new field of the struct and hence I cannot assign a zero.
Example,
ft_table is the new field which can be a 2-D array with varying rows and columns throughout the simulation. So if I assign initially in the beginning of the code as,
bands.ft_table = 0;
then assign 2-D array to it, Simulink throws the below error,
Size mismatch (size [1 x 1] ~= size [:? x 2]).
The size to the left is the size of the left-hand side of the assignment.
Any suggestions how to overcome this?
Fangjun Jiang
el 19 de Sept. de 2018
Editada: Fangjun Jiang
el 19 de Sept. de 2018
In that case, don't use structure. Refer to the document to implement variable-size data.
web(fullfile(docroot, 'simulink/variable-size-data.html'))
Más respuestas (2)
Ankur Soni
el 20 de Mzo. de 2018
1 comentario
Virtualkeeda
el 18 de Ag. de 2018
Hi Ankur, It didnt worked for me.
The same error came for me on this line:
dbn.rbm{3, 1}=[];
"This structure does not have a field 'rbm'; new fields cannot be added when structure has been read or used."
Ver también
Categorías
Más información sobre Low-Level File I/O en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!