フィルターのクリア

Using min() on vectors with double

7 ビュー (過去 30 日間)
Kylie Hansen
Kylie Hansen 2017 年 7 月 6 日
回答済み: PARAS PATIL 2019 年 11 月 6 日
I have several variables of the double type, each around 450x1 in size. I would like to find the minimum value of each of them, but when I use min(vector), MATLAB returns "Subscript indices must either be real positive integers or logicals." Does this mean that min() cannot work with decimals? If so, is there another function I can use that will? An example of my code is below. As you can see, I have set up a matrix that has two columns, one with a single integer and another with the minimum value of the vector.
min_set = [974,min(blg0974);975,min(blg0975);976,min(blg0976)];
Update: All my vectors have positive values with decimal places up to the ten thousandth's place.
  1 件のコメント
Stephen
Stephen 2017 年 7 月 6 日
min should work with double type. The error message you reported and the line supplied leads me to believe there is a variable in your workspace named "min". Is that the case?

サインインしてコメントする。

採用された回答

Geoff Hayes
Geoff Hayes 2017 年 7 月 6 日
編集済み: Geoff Hayes 2017 年 7 月 6 日
Kylie - try typing
which min
to see if min refers to the function to find the minimum value of an array or if min refers to a local variable. If you are seeing the above error message when you call min(vector), then this suggests that you are trying to access elements in an array named min with non-integer indices (which would be the floats or doubles in your vectors/arrays). If this is the case, then you can easily fix this problem by renaming your local variable to something else which will not correspond to a built-in MATLAB function.
  1 件のコメント
Kylie Hansen
Kylie Hansen 2017 年 7 月 6 日
I wasn't familiar with the which command. I've learned something new today! Thank you so much. The issue is solved, and I can go back to work headache-free.

サインインしてコメントする。

その他の回答 (3 件)

dpb
dpb 2017 年 7 月 6 日
"when I use min(vector), MATLAB returns "Subscript indices must either be real positive integers or logicals."
This means you've inadvertently aliased the MIN() function and Matlab now sees min(blg0974) as an array reference.
To confirm this diagnosis, execute
which min
and it will return "min is a variable". To fix this problem, execute
clear min
and remember to not do that again! :)
Illustration of the above to reproduce your symptom:
>> min=min(rand(3)) % call MIN(), forget and name output as min, too...
min =
0.5936 0.2439 0.3485
>> min(min) % try to get overall minimum of the column minima above
Subscript indices must either be real positive integers or logicals.
>>
Oops! Look familiar? :)
>> which min % Whassup???
min is a variable. % Aha! Of course and arrays can't have fractional subscripts
>> clear min % fix the mistake...
>> which min % and back to normal...
built-in (C:\ML_R2014b\toolbox\matlab\datafun\@logical\min) % logical method
>>
  1 件のコメント
Kylie Hansen
Kylie Hansen 2017 年 7 月 6 日
Thank you for such a detailed response. I am familiar with the mistake of naming variables after functions, but I had too many variables in my workspace that I hadn't noticed that I had set it as such. I will definitely keep your advice in mind! Thanks again.

サインインしてコメントする。


Giovanni D'Avanzo
Giovanni D'Avanzo 2017 年 7 月 6 日
what'is blg0974 ?

PARAS PATIL
PARAS PATIL 2019 年 11 月 6 日
nothing

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by