MATLAB 没有足够的输入参数 [英] MATLAB not enough input arguments

查看:36
本文介绍了MATLAB 没有足够的输入参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试运行它,但不知道出了什么问题.我把它保存为 test.m.我在编辑器和 matlab 命令窗口中单击运行,它指出没有足够的输入参数.我觉得我遗漏了一些非常明显的东西,但我无法发现问题.

I keep trying to run this and have no idea what is going wrong. I have it saved as test.m. I click run in the editor and in the matlab command window, it states not enough input arguments. I feel like I am missing something totally obvious, but I cannot spot the issue.

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

推荐答案

它是一个函数(不是脚本),它需要一些输入参数才能运行(在本例中为 Ax),所以你不能点击运行按钮并期望它运行.

It is a function (not an script) and it needs some input arguments to run (in this case A and x), so you cannot hit the run button and expect it to run.

相反,您可以使用 MATLAB 中的命令窗口并输入命令:

Instead you can use the command windows in MATLAB and enter the command:

A = rand(3,3); % define A here
x = ones(3,1); % define x here
test(A,x) % then run the function with its arguments

记住 Ax 应该正确定义.

remember that A and x should be defined properly.

你也可以点击绿色运行按钮旁边的小三角形(见下图),它会显示另一个选项,type command to run.和在那里你可以直接输入相同的命令 test(A,x).之后,每次你为这个函数按下回车键,它就会运行这个命令,而不是只运行没有任何参数的 test 命令.

Also you can hit the little triangle besides the green run button (see the figure below), and it will show you another option, type command to run. And there you can directly enter the same command test(A,x). After that, each time you just hit enter for this function and it runs this command instead of only the test command without any argument.

这篇关于MATLAB 没有足够的输入参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆