Unexpected MATLAB Operator ':'
16 次查看(过去 30 天)
显示 更早的评论
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?
采纳的回答
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Programmatic Model Editing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!