How to redefine enum values as num values to another variable?

5 次查看(过去 30 天)
Hi,
I have the following script to convert enum signal's number values into the values i want to see on the figures. I am having the following error while running it:
>> MEAStest.tcd_enum_currentGear.Data(i)==0
Subscript indices must either be real positive integers or logicals.
How can I make it work?
i=0;
int16(MEAStest.tcd_enum_currentGear.Data);
while i<size(MEAStest.tcd_enum_currentGear.Data)+1
if MEAStest.tcd_enum_currentGear.Data(i)==0
MEAStest.tcd_n_currentGear(i)=0;
elseif MEAStest.tcd_enum_currentGear.Data(i)==11
MEAStest.tcd_n_currentGear(i)=1;
elseif MEAStest.tcd_enum_currentGear.Data(i)==22
MEAStest.tcd_n_currentGear(i)=2;
elseif MEAStest.tcd_enum_currentGear.Data(i)==33
MEAStest.tcd_n_currentGear(i)=3;
elseif MEAStest.tcd_enum_currentGear.Data(i)==44
MEAStest.tcd_n_currentGear(i)=4;
elseif MEAStest.tcd_enum_currentGear.Data(i)==55
MEAStest.tcd_n_currentGear(i)=5;
elseif MEAStest.tcd_enum_currentGear.Data(i)==66
MEAStest.tcd_n_currentGear(i)=6;
elseif MEAStest.tcd_enum_currentGear.Data(i)==77
MEAStest.tcd_n_currentGear(i)=6;
elseif MEAStest.tcd_enum_currentGear.Data(i)==88
MEAStest.tcd_n_currentGear(i)=8;
elseif MEAStest.tcd_enum_currentGear.Data(i)==90
MEAStest.tcd_n_currentGear(i)=9;
elseif MEAStest.tcd_enum_currentGear.Data(i)==160
MEAStest.tcd_n_currentGear(i)=10;
elseif MEAStest.tcd_enum_currentGear.Data(i)==161
MEAStest.tcd_n_currentGear(i)=11;
elseif MEAStest.tcd_enum_currentGear.Data(i)==162
MEAStest.tcd_n_currentGear(i)=12;
elseif MEAStest.tcd_enum_currentGear.Data(i)==163
MEAStest.tcd_n_currentGear(i)=13;
elseif MEAStest.tcd_enum_currentGear.Data(i)==164
MEAStest.tcd_n_currentGear(i)=14;
elseif MEAStest.tcd_enum_currentGear.Data(i)==165
MEAStest.tcd_n_currentGear(i)=165;
elseif MEAStest.tcd_enum_currentGear.Data(i)==166
MEAStest.tcd_n_currentGear(i)=16;
else
MEAStest.tcd_n_currentGear(i)=20;
end
i=i+1;
end

采纳的回答

Guillaume
Guillaume 2023-10-5
编辑:Guillaume 2023-10-5
Hi,
Matlab is one-based indexing. You should change your first line into:
i = 1;
And you should also change your while condition into:
while i<=length(MEAStest.tcd_enum_currentGear.Data)
Because size returns a vector with at least two elements.
You should also consider using a for loop.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Matrix Indexing 的更多信息

产品


版本

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by