Matlab中的函数-未定义的输入参数错误 [英] function in matlab- undefined input argument error

查看:401
本文介绍了Matlab中的函数-未定义的输入参数错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不明白这段代码是什么问题.如果有人可以帮助我,我将很感激.

I can't understand what the problem is with this code. If anyone can help I will be thankful.

function [out] = detj(in1)
%DETJ Summary of this function goes here
%Detailed explanation goes here: N is 2*50 matrix and in1 is scaler
    global N 
    out=(1/8)*(N(1,in1));
end

错误是:

输入参数"in1"未定义.
==> detj在7
时出错 out =(1/8)*(N(1,in1));

Input argument "in1" is undefined.
Error in ==> detj at 7
out=(1/8)*(N(1,in1));

我在另一个文件中定义了N

I defined N in another file

N=importdata('Nodes.txt'); %Matrix of nodes

推荐答案

代码没错,您只是以错误的方式使用了该函数.

No thing wrong with your code, you just used the function the wrong way.

要在Matlab中使用功能,您需要调用它,而不是直接运行它.

To use a Function in Matlab you need to call it, NOT to run it directly.

这是您的原始功能代码

function [out] = detj(in1,in2,in3,in4)
      %DETJ Summary of this function goes here
      %   Detailed explanation goes here %N is 2*50 Matrix
     global N r s
    out=zeros(2,2);
    for m=1:2
    for n=1:2
     out(m,n)=(1/8)*(((N(1,in1)-N(1,in3))*(N(2,in2)-N(2,in4))-(N(2,in1)-N(2,in3))*(N(1,in2)-N(1,in4)))-r(1,m)*((N(1,in3)-N(1,in4))*(N(2,in1)-N(2,in2))-(N(2,in3)-N(2,in4))*(N(1,in1)-N(1,in2)))+s(1,n)*((N(1,in2)-N(1,in3))*(N(2,in1)-N(2,in4))-(N(2,in2)-N(2,in3))*(N(1,in1)-N(1,in4))));
 end
 end
end

要使用您的功能,我尝试了一个简单的代码,

To use your function I tried a simple code,

clc;clear;
global N
global r
global s 
N=ones(2,50);
r=ones(2,2);
s=ones(2,2);
detj(1,2,3,4)

我得到的答案是

ans =

 0     0
 0     0

所以您的函数没什么问题,只是您需要知道如何使用它.

So no thing wrong with your function, just you need to know how to use it.

如果我的回答不清楚,请告诉我,否则祝你好运.

Let me know if my answer is not clear else good luck.

这篇关于Matlab中的函数-未定义的输入参数错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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