matlab

How to call chi2pval from my code


I am trying to use ‘chi2pval’ function in my code but it’s a private function to stats. How can I make it available to me?


Solution

  • chi2pval is a private function that's part of the Stats toolbox. This function does exist in MATLAB, but you aren't able to call it directly as it's located in a private folder that isn't accessible by you... at least not normally. What you can do is search for where the source file is located. You can do that typing in the following command into your Command Prompt:

    which chi2pval -all
    

    which determines where a particular MATLAB function you are looking for is located on your machine. The -all flag displays the paths to all functions that you're looking for. On my Mac OS X machine, this is what I get:

    /Applications/MATLAB_R2013a.app/toolbox/stats/stats/private/chi2pval.m  % Private to stats
    

    You can take a look at the source by invoking edit in front of that string that contains the full path to the function, as well as the function name itself:

    edit /Applications/MATLAB_R2013a.app/toolbox/stats/stats/private/chi2pval.m
    

    When I do this, I see the source code of chi2pval.


    Now, what you can do from here is if you want to actually call chi2pval, you can copy the M-file from this directory to where you are calling your main code, then go ahead and run your code.

    Hope this helps!