Matlab Coder: Table Variables Must be constant

11 次查看(过去 30 天)
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.

更多回答(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