Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9214513
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T01:59:11+00:00 2026-06-18T01:59:11+00:00

I have observed a strange behavior in running the same code in a Matlab

  • 0

I have observed a strange behavior in running the same code in a Matlab function and in the command window. It’s already described in How does scoping in Matlab work? , but I don’t understand how I could solve my specific problem.
The code is the following:

exporteddata.m  %File created by an external program 
                %to export data in Matlab format

surface = struct('vertices', [...]) ; 
                         %I can't specify in the external program 
                         %the name of the variable, it's always "surface"

My actual code is:

   myfunction.m 

   function output = myfunction(input)
   load(input);
   n = size(surface.vertices);
  ....

When running

myfunction('exporteddata.m'); 

I get the following error:

??? No appropriate method, property, or field vertices for class hg.surface.

When running the same instructions from the command window or in debug mode, the code works well.

How can I specify in the function that I need the variable surface present in the workspace, not the Matlab function?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T01:59:12+00:00Added an answer on June 18, 2026 at 1:59 am

    First of all, I must point out that surface is a built-in function in MATLAB, so overloading it is just… bad. Bad, bad, BAD!

    Having said that, the MATLAB interpreter does a pretty good job at resolving variable names and usually tells them apart from function names correctly. So where’s your problem, you ask?
    I believe that you’re using the wrong function: load is a function that loads data from MAT files into the workspace. It is not fit for m-files. By not executing “exportedata.m” properly, surface has never been created as a variable, so MATLAB identifies it as a function name. If you want to execute “exportedata.m”, just type:

    exportedata
    

    and if you want to run the file with the filename stored in input, you can use run:

    run(input)
    

    By executing run(input) from within myfunction, surface should be created in myfunction‘s local scope, and it should work.

    EDIT:
    I’ve just tested it, and the interpreter still gets confused. so the issue of the variable name resolution remains. Here’s a workaround:

    function output = myfunction(input)
       surface = 0;                     %// <-- Pay attention to this line
       run(input);
       n = size(surface.vertices);
    

    Predefining surface allows the interpreter to identify it as a variable throughout your entire function. I’ve tried it and it works.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a view (actually, it's a table valued function, but the observed behavior
I have this form submit code: Event.observe(window, 'load', init, false); function init() { Event.observe('addressForm',
I have observed a strange behavior, I have a XAML Combobox (SilverLight4) declaration with
I am having Xcode 4.5. I have observed a very strange behavior.In previous versions
I have observed that, very infrequently, Internet Explorer (7 or 8, it does not
Input rz value In the head I have: Event.observe(window, 'load', function() { $$(input).each(function(field){ Event.observe(field,
I have observed that windowWillClose is called when the user closes a window but
I have observed some rather inconsistent HTML page rendering behavior when CSS line-height property
I see some strange behavior which I do not understand. I have a helper
I have a strange problem in matching a pattern. Consider the Perl code below

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.