Need to create a matrix with a selection of walking paths with a difficulty degree lower than 3
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I'm being given the following information:
where "routenummer" stands for roadnumber, "gemeente" for city, "afstand" for distance in km and "moeilijkheidsgraad" for difficulty.
I need to create a matrix titled difficultRoads with all of the given information of the walking roads with a difficulty lower than 3. To make this specific matrix I need to use matrix routes (which I've made in my code and consists of the original matrix without the information about the cities).
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)])
As you can see, I also created the vectors nr, afst, gr and the matrix routes. That is an other part of the assignment and can be ignored.
Thanks in advance!
0 commentaires
Réponses (1)
John BG
le 28 Oct 2015
Modifié(e) : John BG
le 13 Fév 2016
Why don't you build a table:
mcell2=table([1;2;3;4;5;6;7;8],{'Mer';'Oud';'Klu';'Kru';'Maa';'Maa';'Klu';'Odu'},[13;12;9.5;4.5;11;12;16;8],[1;3;2;2;3;3;3;2],'VariableNames',{'nr' 'city' 'dist' 'diff'})
find what rows have difficulty below 3:
easy=mcell2.diff<3
tell what to show, in this case you tell to show all fields:
vars={'nr' 'city' 'dist' 'diff'}
And ask:
mcell2(easy,vars)
0 commentaires
Voir également
Catégories
En savoir plus sur Logical dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!