Input argument undefined - MATLAB function/subfunction

后端 未结 2 626
礼貌的吻别
礼貌的吻别 2021-01-24 15:49

I am testing a part of a function for my work in MATLAB. I have defined a function and subfunction as follows(just for testing):

function funct
clear all;
clc;
I         


        
相关标签:
2条回答
  • 2021-01-24 16:22

    I don't have the image processing toolbox, so I can't check this myself, but it looks like nlfilter expects a function of just one argument. Try changing the call to nlfilter like this:

    A = nlfilter(I, [7 7], @(x) dirvar(x,ld));
    
    0 讨论(0)
  • 2021-01-24 16:40

    Chethan is correct in that nlfilter() expects one argument only -- so you need another way to provide the dirvar() function with the ld argument.

    One option is to define the dirvar function as a nested function inside the calling function. I.e.,

    function funct
    % ...
    ld = input('Enter the lag = ') % prompt for lag distance
    A = nlfilter(I, [7 7], @dirvar);
    
    % Subfunction
        function [h] = dirvar(I)
            c = (size(I)+1)/2
            EW = I(c(1),c(2):end)
            h = length(EW) - ld
        end
    
    end
    
    0 讨论(0)
提交回复
热议问题