Unexpected MATLAB Operator ':'
22 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Rhett Green
le 3 Jan 2022
Réponse apportée : Rhett Green
le 20 Jan 2022
I have created a MATLAB Function that I want to be able to read a table that contains the name of Hardware (Column1), Instruction (Column2), and Step (Column3). Each Row represents and instruction for a piece of hardware. The table containing these instructions is in the base workspace and after loading it using evalin to a variable 'x' I want to iterate through each row so I can output the instructions for each piece of hardware accordingly. However when using the ':' operator to interact with the table I receive a "Unexpected MATLAB operator ':' " error. I can index a table using x(1,1) (row 1 column 1) but not by using x(:,1) (all contents of column 1) which worked on the same table in a MATLAB script. Here is the MATLAB script that runs and is what I want to do:
contents = evalin("base","commandSequence");
header = {'Hardware' 'Instruction' 'Step'}
contents.Properties.VariableNames = header;
disp(contents)
Step = 1;
for iRow = 1:Step:height(contents)
hardware1 = contents{iRow,'Hardware'};
hardware = string(hardware1);
switch(string(hardware))
case 'Contactor1'
Instruction = contents{iRow,"Instruction"};
Step = contents{iRow,"Step"};
case 'Contactor2'
Instruction = contents{iRow,"Instruction"};
Step = contents{iRow,"Step"};
case 'Contactor3'
Instruction = contents{iRow,"Instruction"};
Step = contents{iRow,"Step"};
case 'Voltage'
Instruction = contents{iRow,"Instruction"};
Step = contents{iRow,"Step"};
end
end
Any idea what I'm doing wrong and how I can implement something similar in a MATLAB Function block?
3 commentaires
Réponse acceptée
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Class Introspection and Metadata dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!