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

5 views (last 30 days)
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

Accepted Answer

Guillaume
Guillaume on 5 Oct 2023
Edited: Guillaume on 5 Oct 2023
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.

More Answers (0)

Products


Release

R2017b

Community Treasure Hunt

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

Start Hunting!