write a MATLAB code to search for the minimum element value in this array. Write the code to display the index
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Given array a = [9 2 10 12 14 77 5 13], write a MATLAB code to search for the minimum element value in this array. Write the code to display the index and the value of the minimum element. Use for loop for this exercise.
1 comentario
Jan
el 2 de Nov. de 2021
This is a homework question, obviously. Then post, what you have tried so far and ask a specific question. The forum will not solve your home work, but assists you, if you have a question concerning Matlab.
Respuestas (1)
Voss
el 29 de Dic. de 2021
Here's a way to do it with a while loop. Based on this approach, maybe you can come up with a way that uses a for loop instead.
a = [9 2 10 12 14 77 5 13];
min_element = Inf;
min_element_index = 0;
current_index = 1;
while true
try
if a(current_index) < min_element
min_element = a(current_index);
min_element_index = current_index;
end
current_index = current_index+1;
catch
break
end
end
display(min_element);
display(min_element_index);
0 comentarios
Ver también
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!