Problem with logical indexing
古いコメントを表示
I'm trying to write a function that will take a row vector of temperatures as input and will give the number of temperatures below 32° as output. I have tried this:
function numfreeze = freeezing(temperatures)
numfreeze = numel(freezing(freezing<32))
end
...but I get the error message "Out of memory. The likely cause is an infinite recursion within the program."
Can someone help me and tell me what this means? When I just use
numfreeze = numel(freezing(freezing<32))
in the command window after setting a vector for "temperatures", it works fine.
採用された回答
その他の回答 (2 件)
Alex Mcaulley
2019 年 4 月 24 日
I think you have a typo, calling infinite times the function freezing, then:
function numfreeze = freeezing(temperatures)
numfreeze = numel(temperatures(temperatures<32))
end
Ajith Thomas
2019 年 7 月 19 日
function numfreeze=freezing(w)
lowerthan_32=w(w<32);
no_logical_values=lowerthan_32(lowerthan_32>=0);
numfreeze=length(no_logical_values);
end
1 件のコメント
Ajith Thomas
2019 年 7 月 19 日
function numfreeze=freezing(w)
lowerthan_32=w(w<32);
numfreeze=numel(lowerthan_32);
end
カテゴリ
ヘルプ センター および File Exchange で Logical についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!