Matlab Coder: Table Variables Must be constant

조회 수: 18 (최근 30일)
Robert Jack
Robert Jack 2020년 7월 30일
댓글: Sidharth Vasumithran 2021년 4월 12일
I can't find any easy to follow help in regards to the Matlab coder. So this is likely a very simple solution.
Trying to use the Matlab Coder and using a test function to try and practice but also to prove that what we have can be used for C++
Basically I have a .mat file which holds a table called Batches
The script is simply
% Load test data
BatchMat = load('batches.mat')
% Determine closest and farthest points and corresponding distances
TestFunc(BatchMat);
with the function being
function TestFunc(BatchMat) %#codegen
% Define seperate Input and Output Batches
InputBatches = BatchMat.batches;
OutputBatches = BatchMat.batches;
% Apply Random number
H = size(InputBatches.PDWs{1,1}.PulseAmplitude_dBm,1);
RandValue = randi([-100,-50],H,1);
OutputBatches.PDWs{1,1}.PulseAmplitude_dBm(:,1) = RandValue; % Randomise the values
% Plotting the Graph
x1 = InputBatches.PDWs{1,1}.Urn;
y1 = InputBatches.PDWs{1,1}.PulseAmplitude_dBm;
x2 = InputBatches.PDWs{1,1}.Urn;
y2 = OutputBatches.PDWs{1,1}.PulseAmplitude_dBm;
plot(x1,y1,'r',x2,y2,'k')
end
I keep getting the error "When indexing a table using variable names, the names of the table variables must be constant"
BatchMat.batches is a table but what the point of the function is that it will accept any size table with the same column names.
Any help please.
  댓글 수: 2
Robert Jack
Robert Jack 2020년 7월 30일
편집: Robert Jack 2020년 7월 30일
Table is a 50x9 table
Last column holds Tables of N x 32 size
Denis Gurchenkov
Denis Gurchenkov 2020년 7월 30일
Hi Robert, can you please attach batches.mat? If you are using MATLAB Coder, please specify how do you invoke it. What is the command line parameters you pass to codegen, or the .prj file if you use the UI?

댓글을 달려면 로그인하십시오.

채택된 답변

Gaurav Garg
Gaurav Garg 2020년 8월 13일
Hey Robert,
To index into a table using variables names, first make the table constant by using the coder.Constant function.
By default, tables that you pass into generated code as input arguments are not constant. Even their variable and row names are not constant. If a table is not constant, then indexing by using variable or row names produces an error. You can index into a table using numeric or logical indices even if it is not constant.
Kindly refer to the doc here for any help.
  댓글 수: 1
Sidharth Vasumithran
Sidharth Vasumithran 2021년 4월 12일
Can you elaborate on how it is done,preferably with the help of an example?

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 MATLAB Coder에 대해 자세히 알아보기

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by