Info

この質問は閉じられています。 編集または回答するには再度開いてください。

Can I scan 10 arrays all together to find one smallest value between all arrays?

1 回表示 (過去 30 日間)
ME
ME 2015 年 4 月 26 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
I have 10 arrays.I need to be able to find the smallest value. I want to find another way of doing this rather than combining all 10 arrays into 1 and then scanning them.
  2 件のコメント
Stephen23
Stephen23 2015 年 4 月 26 日
Do you mean:
  • the smallest value that is common to all arrays, or
  • the smallest value found within any one (or more) of the arrays?
  • or something else?
ME
ME 2015 年 4 月 26 日
編集済み: ME 2015 年 4 月 26 日
one smallest value from all the arrays

回答 (2 件)

Stephen23
Stephen23 2015 年 4 月 26 日
編集済み: Stephen23 2015 年 4 月 26 日
Basically you have to choose whether you combine the values or take the minimum first. Each of these has different advantages, so it depends on what you are trying to achieve:
  1. Combine them into one array Z = [A,B,C,...] and then call min(Z(:)). This is likely to be the fastest and neatest code.
  2. Combine the minimum of each Y = [min(A(:)),min(B(:)),...] and then min(Y).

Jan
Jan 2015 年 4 月 26 日
編集済み: Jan 2015 年 4 月 26 日
You can solve this with a loop in a flexible way:
function MinValue = MinOfList(varargin)
MinValue = min(varargin{1}(:));
for k = 2:nargin
MinValue = min(min(varargin{k}(:)), MinValue);
end
Now call this like:
m = MinOfList(rand(3), rand(7), -1, 1:12)

この質問は閉じられています。

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by