Given two input vectors: name - user last names age - corresponding age of the person.Return the name of the oldest person in the output var old_name.Why am I getting error?
11 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Given two input vectors:
- name - user last names
- age - corresponding age of the person
Return the name of the oldest person in the output variable old_name.
6 comentarios
Dyuman Joshi
el 24 de Jun. de 2022
1 - There is no function as max_age.
2 - Age is an array of numbers. You have to find the maximum age and return the corresponding name. Suppose, the 3rd element in the age array is the largest, so it is asking you to submit the 3rd element from the name array.
3 - The question is not asking you to display the name. It is asking you to return the name (character arraystring)
Respuestas (4)
Maharnab
el 9 de Nov. de 2022
function old_name = find_max_age(name,age)
old_name=name(find(age==max(age)));
end
0 comentarios
Aniruddh Maini
el 30 de Jun. de 2022
Hi Devleena, following function can be used to find the name of oldest person.
function oldest_name = findOldest(name,age)
len = length(name);
Max_age = -1;
Max_index = -1;
for i = 1:len
if(age(1,i)>Max_age)
Max_age = age(1,i);
Max_index = i;
end
end
oldest_name = name(1,Max_index);
end
Hope it helps !
Iman
el 2 de En. de 2023
close all;
clear all;
clc;
function oldest_name = findOldest(name,age)
len = length(name);
Max_age = -1;
Max_index = -1;
for i = 1:len
if(age(1,i)>Max_age)
Max_age = age(1,i);
Max_index = i;
end
end
oldest_name = name(1,Max_index);
end
1 comentario
Ver también
Categorías
Más información sobre Entering Commands en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!