0

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

The error is :

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

I defined N in another file

N=importdata('Nodes.txt'); %Matrix of nodes
3
  • 1
    If you wish to get answer, I would advise to split up the statement where your error is occurring as well as give an example of inputs. I.e, what do in1, in2, in3, in4, N, r, s, look like? How are you calling this function? Commented Jul 27, 2017 at 14:34
  • 1
    It seems you are calling detj without any input argument Commented Jul 27, 2017 at 14:38
  • As Durkee suggested, add the part of your main script where you call the function detj and where you create N and in1 variables. Commented Jul 27, 2017 at 14:48

1 Answer 1

1

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

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

This is your original function code

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)

And I got answer as

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.

Sign up to request clarification or add additional context in comments.

2 Comments

my bad, so if we run a function it doesn't matter that we get an error?
Yes exactly, actually I don't see any reason to run a function. Just make sure you save your function every time you make change to it

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.