write a MATLAB code to search for the minimum element value in this array. Write the code to display the index
显示 更早的评论
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 个评论
Jan
2021-11-2
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.
回答(1 个)
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);
类别
在 帮助中心 和 File Exchange 中查找有关 Axes Transformations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!