how to create wind direction categoricals

Hello. I m trying to create categoricals from wind directions (0 - 359 degrees) for 4 values: 1 = airport; 2 = bus_sta; 3= road; 4 = other
The compass degree ranges, resectively, are below, in a for loop, which did not work. I want to store the vlues in a vector of length specifed:
for i = 1:length(T1.classification)
if (45<=RMET2.Deg)&(RMET2.Deg<=65)
impact = impact(i);
elseif (260<=RMET2.Deg)&(RMET2.Deg<=280)
impact = impact(i);
elseif (80<=RMET2.Deg)&(RMET2.Deg<=100)
impact = impact(i);
else impact = impact;
end
end

5 commentaires

the cyclist
the cyclist le 13 Mar 2023
Can you upload the input data? (You can use the paper clip icon in the INSERT section of the toolbar.) That would make it easier to help debug the code.
impact = impact(i);
You are overwriting the complete array with a single element of the array, leaving it a scalar. The next iteration would fail.
% Wind impact sector (test Mar 12, 2023)---------------------------
ImpactLogan = any(45<=RMET2.Deg)&(RMET2.Deg<=65); % ref: Hudda et al., 2016
%isLogan = ImpactLogan==1;
ImpactBus = any(260<=RMET2.Deg)&(RMET2.Deg<=280);
%isBus = ImpactBus ==2;
ImpactRoad = any(80<=RMET2.Deg)&(RMET2.Deg<=100);
%isRoad = ImpactRoad ==3;
impact = ([ImpactLogan, ImpactBus, ImpactRoad]); % ?????
Impact_Wind = categorical(impact,[0 1 2 3],{'other' 'airport' 'bus_sta' 'road'})
RMET2 = addvars(RMET2, impact);
I tried this approach too
here is the vector file in a column

Connectez-vous pour commenter.

 Réponse acceptée

RMET2.Deg = (0:15:360).';
dirs = discretize(RMET2.Deg, [0 45 65 80 100 260 280 360], {'other', 'airport', 'other', 'bus_sta', 'other', 'road', 'other'});
disp(table(RMET2.Deg, dirs))
Var1 Var2 ____ ___________ 0 {'other' } 15 {'other' } 30 {'other' } 45 {'airport'} 60 {'airport'} 75 {'other' } 90 {'bus_sta'} 105 {'other' } 120 {'other' } 135 {'other' } 150 {'other' } 165 {'other' } 180 {'other' } 195 {'other' } 210 {'other' } 225 {'other' } 240 {'other' } 255 {'other' } 270 {'road' } 285 {'other' } 300 {'other' } 315 {'other' } 330 {'other' } 345 {'other' } 360 {'other' }

3 commentaires

Thank you Walter
This worked for me:
catnames = ["other", "airport", "other", "bus_sta", "other", "road", "other"];
ImpactWind = discretize(RMET2.Deg,[0 45 65 80 100 260 280 360],'categorical',catnames);
That looks good.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

Produits

Version

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by