I have to do a single index for the North
2 views (last 30 days)
Show older comments
Valerio Gianforte
on 3 Mar 2020
Commented: Valerio Gianforte
on 3 Mar 2020
Hi everyone,
I sould to do a single index for the North, I done two index because the North sector start from 337.5 and finishes with a value of 22.5. Is there a way to join North1 and North2? Thanks.
%fileName = 'D:\Valerio\data\test.mat';
fileName = 'D:\Valerio\data\IPCC_data_models\ACCESS1_0.mat';
loadfile = load(fileName);
table = loadfile.table_def;
%time_table = table2timetable(loadfile.table_def);
date_array = table.YYMMDD;
hour_array = table.HH;
Hs = table.Hs_tot;
Tm = table.Tm_tot;
Dm = table.Dm_tot;
date_num = datenum(date_array);
North1 = find(Dm >= 337.5 & Dm <= 360.0);
North2 = find(Dm >= 0.0 & Dm <= 22.5);
North_East = find(Dm >=22.5 & Dm <= 67.5);
East = find(Dm >=67.5 & Dm <= 112.5);
South_East = find(Dm >=112.5 & Dm <= 157.5);
South = find(Dm >=157.5 & Dm <= 202.5);
South_West = find(Dm >=202.5 & Dm <= 247.5);
West = find(Dm >=247.5 & Dm <= 292.5);
North_West = find(Dm >=292.5 & Dm <= 337.5);
Hs_N1 = Hs(North1);
Hs_N2 = Hs(North2);
Hs_NE = Hs(North_East);
Hs_E = Hs(East);
Hs_SE = Hs(South_East);
Hs_S = Hs(South);
Hs_SW = Hs(South_West);
Hs_W = Hs(West);
Hs_NW = Hs(North_West);
Tm_N1 = Tm(North1);
Tm_N2 = Tm(North2);
Tm_NE = Tm(North_East);
Tm_E = Tm(East);
Tm_SE = Tm(South_East);
Tm_S = Tm(South);
Tm_SW = Tm(South_West);
Tm_W = Tm(West);
Tm_NW = Tm(North_West);
0 Comments
Accepted Answer
Hank
on 3 Mar 2020
Instead of using find, to get the index, just use boolean indexing. This allows you to combine North1 and North2 with a logical or
North1 = Dm >= 337.5 & Dm <= 360.0; % Left of north, boolean array
North2 = Dm >= 0.0 & Dm <= 22.5; % Right of north, boolean array
Hs_N = Hs( North1 | North2 ); % | performs logical or of North1 and North2
Alternatively
North = (Dm >= 337.5 & Dm <= 360.0) | (Dm >= 0.0 & Dm <= 22.5);
Hs_N = Hs(North);
More Answers (0)
See Also
Categories
Find more on Resizing and Reshaping Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!