How can I make MATLAB to ignore a function?

VolkanOzcan

My problem is, even though there is a local variable called 'mu', when code runs the command

sqrt(mu)

Matlab tries to run the internal function called mu.

As far as I know this is not a normal behaviour. How can I make Matlab to use the local variable over it's internal function?

I plan to compile this code with deploy tool, therefore modifying matlab's internal function file is not suitable. Problem will occur in complied version.

Let me give more detail about the problem,

My main.m file calls function_a.m function. Function_a function runs another script named, constants . Constants.m file is not a function but a script, it only keeps some variables so when its loaded it fills workspace with those variables. It's format is,

const1=3; const2=5; mu=2;

Right after function_a runs constant.m, it tries to use the mu value. This is when matlab gives an error from it's internal mu function. It means that Matlab does not use local mu variable which was created by contants.m.

I used debugger to stop the code after running constant.m but before using mu in a command. Mu is actually in work space as it should be. While in debug mode, if I use the command sqrt(mu), it works as it should be. But when I let continue to run, when same command is written in function file, Matlab gives the error that shows it is trying to use the internal function.

How can I fix this?

Suever

First of all, there is no internal function named mu so I don't know what the confusion is there.

The issue is likely happening because you have used mu as a function and then within the Constants script, you use it as a variable and MATLAB's static code analyzer gets confused so it goes with it's first usage as a function. This is the same issue that you'd encounter if you called load and tried to load a variable with the name of a function into the current workspace.

But in general, to avoid issues like this, you should avoid using a script like Constants.m to populate the workspace of the calling function. This is because you end up with this ambiguity if the calling function's workspace contains functions or variables with the same name. A better approach would be to make Constants a function and have it return a struct which can then be used to access the constant variables

function S = Constants
    S.const1 = 3;
    S.const2 = 5;
    S.mu = 2;
end

Then from within the calling function

constants = Constants();

% Use the constants
value = constants.const1 + constants.mu;

% Or assign them to "safe" variables that are specific to this calling function
my_mu = constants.mu;

In this way, mu from Constants.m doesn't always have to be called mu which leads to more robust and reusable code.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How can I make IBus not ignore ~/.XCompose?

From Dev

How can I make IBus not ignore ~/.XCompose?

From Dev

Matlab: How I can make this transformation on the matrix A?

From Dev

Matlab: How I can make this transformation on the matrix A?

From Dev

How do I make the sorted function ignore some characters?

From Dev

How can I make ssh ignore .ssh/config?

From Dev

How Can I Make Git Ignore Rails Assets?

From Dev

How can I make gitweb ignore whitespace changes?

From Dev

How can I make PHPUnit ignore a file pattern?

From Dev

How can I make ssh ignore .ssh/config?

From Dev

How can I make NetworkManager ignore my wireless card?

From Dev

How can I make ignore path with slash in PHP?

From Dev

How can I make sed delete a line then ignore the test of the file?

From Dev

MATLAB: How can I plot the Probit function?

From Dev

How can I ignore certain strings in my string centring function?

From Dev

How can I make a Self Containing Function?

From Dev

How can I make this refers to the class in the function?

From Dev

How can i make a function for a certain textfield?

From Dev

How can I make this function acccording to timezone?

From Dev

Can I tell Make to ignore environment variables?

From Dev

Can I make davfs ignore untrusted certificates?

From Dev

How can I make echo or printf in shell ignore a double backslash (\\) and print it as I see it

From Dev

How can I make the following function into a tail-recursive function?

From Dev

How can I create multiple inputs for a matlab function block?

From Dev

How can I pass data to the MATLAB oncleanup function?

From Dev

How can I check since which Matlab version a function exists?

From Dev

How can I get workspace variables in MATLAB Function?

From Dev

How can I create a probability density function in Matlab?

From Dev

How can I perfect out my zigzag matlab function?

Related Related

  1. 1

    How can I make IBus not ignore ~/.XCompose?

  2. 2

    How can I make IBus not ignore ~/.XCompose?

  3. 3

    Matlab: How I can make this transformation on the matrix A?

  4. 4

    Matlab: How I can make this transformation on the matrix A?

  5. 5

    How do I make the sorted function ignore some characters?

  6. 6

    How can I make ssh ignore .ssh/config?

  7. 7

    How Can I Make Git Ignore Rails Assets?

  8. 8

    How can I make gitweb ignore whitespace changes?

  9. 9

    How can I make PHPUnit ignore a file pattern?

  10. 10

    How can I make ssh ignore .ssh/config?

  11. 11

    How can I make NetworkManager ignore my wireless card?

  12. 12

    How can I make ignore path with slash in PHP?

  13. 13

    How can I make sed delete a line then ignore the test of the file?

  14. 14

    MATLAB: How can I plot the Probit function?

  15. 15

    How can I ignore certain strings in my string centring function?

  16. 16

    How can I make a Self Containing Function?

  17. 17

    How can I make this refers to the class in the function?

  18. 18

    How can i make a function for a certain textfield?

  19. 19

    How can I make this function acccording to timezone?

  20. 20

    Can I tell Make to ignore environment variables?

  21. 21

    Can I make davfs ignore untrusted certificates?

  22. 22

    How can I make echo or printf in shell ignore a double backslash (\\) and print it as I see it

  23. 23

    How can I make the following function into a tail-recursive function?

  24. 24

    How can I create multiple inputs for a matlab function block?

  25. 25

    How can I pass data to the MATLAB oncleanup function?

  26. 26

    How can I check since which Matlab version a function exists?

  27. 27

    How can I get workspace variables in MATLAB Function?

  28. 28

    How can I create a probability density function in Matlab?

  29. 29

    How can I perfect out my zigzag matlab function?

HotTag

Archive