I have to do a single index for the North

조회 수: 1 (최근 30일)
Valerio Gianforte
Valerio Gianforte 2020년 3월 3일
댓글: Valerio Gianforte 2020년 3월 3일
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);

채택된 답변

Hank
Hank 2020년 3월 3일
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);
  댓글 수: 1
Valerio Gianforte
Valerio Gianforte 2020년 3월 3일
Ok, thanks. The second way works perfectly

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

제품


릴리스

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by