Hello, Im trying to evaluate and separete by categories a certain Variable (Acceleration) and dividing it by levels (0,1,2,3) depending on its value to therefor do a table with them, however my code isnt really working, only obtain 1 value, which 0, when im expecting to get a 621x1 array. Leve here my code, if anyone can help i would appreciate.
Thank you.
Acceleration_Value= abs(Acceleration); % Obtaining absolute values for acceleration/deceleration
ds_mapping=[];
if 0.7 <= Acceleration_Value >= 2.79
ds_mapping= 'Econimic (1)';
elseif 2.79 < Acceleration_Value >= 3.63
ds_mapping= 'Normal (2)';
elseif 3.63 < Acceleration_Value >= 6.5
ds_mapping= 'Agressive (3)';
else
ds_mapping= 0
end
Table1= table(Acceleration_Value, ds_mapping)

Réponses (1)

Walter Roberson
Walter Roberson le 8 Mar 2021

0 votes

In MATLAB,
if 0.7 <= Acceleration_Value >= 2.79
is considered to be
if all((0.7 <= Acceleration_Value) >= 2.79)
The first part, (0.7 <= Acceleration_Value) returns 1 (true) for each element of Acceleration_Value that is greater than or equal to 0.7, and 0 for each element that is not. Then the 0 or 1 is compared to 2.79... and of course that will never be true.
Your use of table() suggests to me that your Acceleration is a vector rather than a scalar.
I would suggest you consider using discretize() with categorical
(and remember that table want column vectors not row vectors.)

Catégories

Community Treasure Hunt

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

Start Hunting!

Translated by