私は次の情報を与えられています:
"routenummer" は道路番号、"gemeente" は都市、"afstand" は距離 (km)、"moeilijkheidsgraad" は難易度を表します。
難易度が 3 未満の徒歩道路のすべての情報を含む、hardRoads というタイトルのマトリックスを作成する必要があります。この特定のマトリックスを作成するには、マトリックス ルートを使用する必要があります (コードで作成し、元の都市に関する情報を含まないマトリックス)。
n = 0;
nr = [1; 2; 3; 4; 5; 6; 7; 8]
afst = [13; 13; 9.5; 4.5; 11; 12; 16; 8]
gr = [1; 3; 2; 2; 3; 3; 3; 2]
routes = zeros(8, 3);
routes(:,1) = nr;
routes(:,2) = afst;
routes(:,3) = gr;
routes
for r = 1:8
if routes(r,2) > 10
n = n + 1;
end
end
for r = 1:8
sel= (routes(r,3) < 3)
% I have no clue on what to do here, gr(sel)
% doesn't seem to work and I have no idea how
% I could turn it into a matrix aswell with
% only the extra information of the required roads.
end
disp(['The number of roads with a distance bigger than 10 km is ' num2str(n)])
ご覧のとおり、ベクトル nr、afst、gr、およびマトリックス ルートも作成しました。これは割り当ての別の部分であり、無視できます。
実行すると、マトリックスは次のように形成されます
1 Merelbeke 13 1
3 Kluisbergen 9.5 2
4 Kruishoutem 4.5 2
8 Oudenaarde 8 2
前もって感謝します!