フィルターのクリア

Info

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

Function definitions are not permitted in this context. is the error

2 ビュー (過去 30 日間)
Praveen  kumar
Praveen kumar 2016 年 3 月 9 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
function y=minutie(x)
i=ceil(size(x)/2);
if x(i,i)==0;
Y=0;
else
Y=sum(x(:))-1;
end
  1 件のコメント
Image Analyst
Image Analyst 2016 年 3 月 9 日
Please complete your question.

回答 (1 件)

Walter Roberson
Walter Roberson 2016 年 3 月 9 日
size(x) is a vector, even when x is a scalar or a vector. So i=ceil(size(x)/2) will have i be a vector. Then you use x(i,i) which is indexing x with that vector at each of the two indices, which would be a request to test 4 different locations (a 2 x 2 subarray). This would also fail if x is more than twice as long as it is wide or more than twice as wide as it is long.
Instead, check x(i(1), x(i(2))
Or, more simply, check
x( ceil(numel(x)/2) )
as that spot is going to be right in the middle of the array

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

Community Treasure Hunt

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

Start Hunting!

Translated by