Effacer les filtres
Effacer les filtres

Matlab Coder: Table Variables Must be constant

11 vues (au cours des 30 derniers jours)
Robert Jack
Robert Jack le 30 Juil 2020
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 commentaires
Robert Jack
Robert Jack le 30 Juil 2020
Modifié(e) : Robert Jack le 30 Juil 2020
Table is a 50x9 table
Last column holds Tables of N x 32 size
Denis Gurchenkov
Denis Gurchenkov le 30 Juil 2020
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?

Connectez-vous pour commenter.

Réponse acceptée

Gaurav Garg
Gaurav Garg le 13 Août 2020
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 commentaire
Sidharth Vasumithran
Sidharth Vasumithran le 12 Avr 2021
Can you elaborate on how it is done,preferably with the help of an example?

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur MATLAB Coder dans Help Center et File Exchange

Produits


Version

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by