How can I make a code to list all the student's name whose weight is greater than 71kg?
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Kiha Kim
le 14 Déc 2021
Modifié(e) : Walter Roberson
le 14 Déc 2021
Student = struct('Name', ...
{'William','Romi','Russel','Mackly','Julia','Nimo','Bond','Mike','Rossel','Collom'}, ...
'Height', ...
{174,168,182,166,156,172,171,163,166,174}, ...
'Weight', ...
{76,62,72,60,62,80,90,48,56,72}, ...
'Gender', ...
{'M','F','M','M','F','F','M','M','F','M'})
0 commentaires
Réponse acceptée
Image Analyst
le 14 Déc 2021
Try this:
Student = struct('Name',{'William','Romi','Russel','Mackly','Julia','Nimo','Bond','Mike','Rossel','Collom'},'Height',{174,168,182,166,156,172,171,163,166,174},'Weight',{76,62,72,60,62,80,90,48,56,72},'Gender',{'M','F','M','M','F','F','M','M','F','M'})
% Find which indexes have a weight of > 71
indexes = find([Student.Weight] > 71)
% List their names
for k = 1 : length(indexes)
thisIndex = indexes(k);
thisName = Student(thisIndex).Name;
fprintf('%s weighs %d kg.\n', thisName, Student(thisIndex).Weight)
end
0 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Other Formats 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!