I am trying to provide two parameters to the fun
argument of nlfilter
function. I would like to do this by using a handle to the function assign_value
I created. This is my function:
function y = assign_value(x, ii)
index= x([1 2 3 4 6 7 8 9]);
if ismember(ii, index)==1
x(5)= ii; % 'ii' is the cloud object ID
end
y=x;
end
I already red some MATLAB documentation (e.g. 1, 2, 3), and saw some answers (4, 5, etc.), but I still would need a help to solve my specific problem in order to understand how handles to functions work.
Here is what I'm trying to do (x
is a 9by9 double-class matrix)
ii= 127
y= nlfilter(x, [3 3], @assign_value)
The error I get is:
??? Subscripted assignment dimension mismatch.
Error in ==> nlfilter at 75
b(i,j) = feval(fun,x,params{:});
Any help would be really appreciated, thanks in advance.
ANSWER
Thanks to Acorbe comments,I finally make it. As my y
output of assign_value
function was an array, and the fun
parameter of nlfilter
has to output only scalars, I changed my function to:
function y = assign_value(x, ii)
index= x([1 2 3 4 6 7 8 9]);
if ismember(ii, index)==1
x(5)= ii; % 'ii' is the cloud object ID
end
y=x(5);
end
And doing:
y= nlfilter(x, [3 3], @(x) assign_value(x, ii));
my result is fine. Thanks again to Acorbe for his precious contribution.