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)

답변 (1개)

Walter Roberson
Walter Roberson 2021년 3월 8일

0 개 추천

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.)

카테고리

도움말 센터File Exchange에서 Call Python from MATLAB에 대해 자세히 알아보기

질문:

2021년 3월 8일

답변:

2021년 3월 8일

Community Treasure Hunt

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

Start Hunting!

Translated by