フィルターのクリア

Min Returns Value That is Not in List

1 回表示 (過去 30 日間)
Paul Huter
Paul Huter 2014 年 9 月 25 日
コメント済み: Paul Huter 2014 年 9 月 25 日
I have a cell array and I am trying to find the min (and max) value. The numbers in the cell array go from 2 to over 200 (but not necessarily all numbers). However, when I try to find the min (using "cellfun" or "cat2mat"), I get 48 as the min and 57 as the max. Neither 48 nor 57 is in my list of values.
Any ideas on what the issue is?
  2 件のコメント
Guillaume
Guillaume 2014 年 9 月 25 日
Can you give an example of your cell array?
Paul Huter
Paul Huter 2014 年 9 月 25 日
It is a single column with about 226 values.

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

採用された回答

Geoff Hayes
Geoff Hayes 2014 年 9 月 25 日
Paul - are you somehow converting your numbers to strings? Try the executing the following statements in the Command Window
min('104')
ans =
48
and
max('191')
ans =
57
The ASCII code for zero is 48, and the ASCII code for 9 is 57. What is the line of code you are using with cellfun?
  2 件のコメント
John D'Errico
John D'Errico 2014 年 9 月 25 日
編集済み: John D'Errico 2014 年 9 月 25 日
+1. I would bet a decent sum of money that you got it right. The clue being the statement that the cell array contains "not necessarily all numbers". So it must be a cell array containing strings. Just because something LOOKS like a number does not mean it is stored as such, or that it would be interpreted as a number by MATLAB.
Paul Huter
Paul Huter 2014 年 9 月 25 日
That was the path I was heading down after I posted this. I got things working with min(cellfun(@str2num, ARRAY)).
Thank you.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMatrices and Arrays についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by