Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/matlab/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
MATLAB输入它不是一个双重错误_Matlab_Linear Algebra - Fatal编程技术网

MATLAB输入它不是一个双重错误

MATLAB输入它不是一个双重错误,matlab,linear-algebra,Matlab,Linear Algebra,我的文件不工作,我不知道为什么。 当我在delcare之后运行y=测试(A,x)时: A=地板(兰特(8100)) x=地板(兰特(100,1)) 对于类型为“double”的输入参数,我得到了未定义的函数“test” function [ output_args ] = untitled2( ~ ) function y = test(A, x) %This function computes the pro duct of matrix A by vector

我的文件不工作,我不知道为什么。 当我在delcare之后运行y=测试(A,x)时:

A=地板(兰特(8100))

x=地板(兰特(100,1))

对于类型为“double”的输入参数,我得到了未定义的函数“test”

function [ output_args ] = untitled2( ~ )
    function y = test(A, x)
    %This function computes the pro
    duct of matrix A by
    vector x row-wise
    % define m number of rows here to feed into for loop
    [ma,na] = size(A);
    [mx,nx] = size(x);
    % use if statement to check for proper dimensions
    if(na == mx && nx == 1)
    y = zeros(ma,1);   % initialize y vector for n = 1:ma
    y(n) = A(n,:)*x;
    %end
    else
    disp('Dimensions of matrices do not match')
    y = [];
    end
    end
    end

正如Ben Voigt在评论中正确地告诉您的,您的问题是测试是在untitled2中定义的

对于您发布的代码,没有必要做这样的事情,因此您可以通过在没有外部untitled2的情况下声明test来解决问题。所以只需创建一个test.m文件,只需使用这部分代码

function y = test(A, x)
    %This function computes the product of matrix A by vector x row-wise
    % define m number of rows here to feed into for loop
    [ma,na] = size(A);
    [mx,nx] = size(x);
    % use if statement to check for proper dimensions
    if(na == mx && nx == 1)
        y = zeros(ma,1);   % initialize y vector 
        for n = 1:ma
            y(n) = A(n,:)*x;
        end
    else
       disp('Dimensions of matrices do not match')
       y = [];
    end
end

然后再次调用函数

您不能从命令窗口调用嵌套函数,只能调用顶级函数。那么,我如何解决这个问题?我不熟悉这种语言,所以我这样做了,它说第4行:没有足够的输入行参数。代码的一部分在注释行中。我已经在上面显示的代码中修复了它。尝试复制粘贴并再次执行。好的,现在当我运行它时,我得到了。mfile(第11行)中的错误y(n)=A(n,:)*x;我已经复制粘贴了上面的代码,它正在工作。所以你可能在我上面写的过程中犯了一些错误,仔细检查每一步。在任何情况下,你现在的问题都不直接与问题有关,如果你仍然有问题,即使在另一个诚实的努力,试图找出错误(再次,它的工作对我来说),请考虑打开另一个问题。