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!