0

I run the main code that needs some subcodes in specific folders that are located within the working directory. I add these folders with the following commands:

addpath('./k_means');
addpath('./pb');

The error message when the main file (in the current working directory) tries to read subcodes in the above directories.

Undefined function or variable 'demo_pb'.

What's the fix for that?

5
  • You can use mfilename('fullpath') to get the current folder of the currently running script. From those path create the fullpath of your two subfolder.
    – obchardon
    Commented Nov 14, 2019 at 17:12
  • @obchardon, all folders are located in the currently running code directory and the current directory that is obtained with "cd" command is as the same with the currently running code .
    – Ben25
    Commented Nov 14, 2019 at 17:31
  • Using the fullpath is, IMO, safer. With the few information provided, it's hard to help you more. Where is the demo_pb function stored ? And how do you call those function ?
    – obchardon
    Commented Nov 14, 2019 at 17:33
  • @obchardon, "demo_pb" is stored in the "pb" folder and it is called as follows: pb_im=demo_pb(input_im);
    – Ben25
    Commented Nov 14, 2019 at 17:37
  • 1
    For debugging the problem: 1. Remove the addpath('./pb');. 2. Before pb_im=demo_pb(input_im);, replace it with the command: cd('./pb');. 3. Place a breakpoint at the cd('./pb'); line and execute code until stop at breakpoint. 4. Single step (press F10). 5. Verify the current folder is pb and the file demo_pb.m is in the folder. 6. Step into demo_pb (press F11), and see if it works.
    – Rotem
    Commented Nov 14, 2019 at 18:51

0

Your Answer

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

Browse other questions tagged or ask your own question.