我收到以下信息:
其中“routenummer”代表道路编号,“gemeente”代表城市,“afstand”代表距离(公里),“moeilijkheidsgraad”代表难度。
我需要创建一个名为 hardRoads 的矩阵,其中包含难度低于 3 的步行道路的所有给定信息。要制作这个特定的矩阵,我需要使用矩阵路线(我在我的代码中制作并由原始没有城市信息的矩阵)。
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
提前致谢!