1

Can anyone tell me why the following code

function s3()

   function ret = fun(x)
       disp(x);
       ret = 0;
   end

  fun(1);

end

produces "Attempt to reference field of non-structure array.". I have this code in a file called s3.m. If I run this in the editor using the play button it runs fine. If I enter s3.m on the command line it produces the above error. Thanks for any help in advance!

4
  • 3
    the n-th: Possibly 'clear all' might help. Is there a variable called 's3' in your workspace? Commented Jan 4, 2011 at 8:50
  • 2
    You must type not s3.m but s3() in the command line to run the function s3 Commented Jan 4, 2011 at 11:08
  • 5
    You asked this same question on the matlab newsgroup. The answer there is you are probably trying to run your function by calling s3.m in the command window. This is not how you execute a function in matlab. If you are going to ask a question, at least read the responses! Commented Jan 4, 2011 at 11:25
  • 1
    Calling s3.m on the command line yields the following error message: '??? Undefined variable "s3" or class "s3.m".' Commented Jan 4, 2011 at 16:53

1 Answer 1

5

Call it this way:

s3()

rather than

s3.m

because it's a function you have created.

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

Comments

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.