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 个评论
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
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.
1 个评论
Sidharth Vasumithran
2021-4-12
Can you elaborate on how it is done,preferably with the help of an example?
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!