MATLAB输入参数不足 [英] MATLAB not enough input arguments

查看:2388
本文介绍了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).之后,每次您按下此功能的Enter键,它就会运行此命令,而不是仅运行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天全站免登陆