Import error in MATLAB - matlab

I'm brand new to MATLAB and am having trouble importing a module called sigTOOL. My code:
>> path('/space/jazz/1/users/gwarner/sigTOOL/program')
>> sigTOOL
returns:
Undefined function 'fileparts' for input arguments of type 'char'.
Error in sigTOOL (line 72)
parentdirectory=fileparts(which('sigTOOL'));
The weirdest part is that I've actually been able to open this successfully before. I used the same code and haven't edited the sigTOOL directory or changed it's path since. Any ideas?

Your usage of path is wiping out MATLAB's default search path.
If you change the first line to
path(path,'/space/jazz/1/users/gwarner/sigTOOL/program')
the path will be added to the bottom of the search stack. You can add the directory to the top of the stack by using addpath:
addpath('/space/jazz/1/users/gwarner/sigTOOL/program')

Related

Error message "using openfig" with Matlab 2018b and Octave

I am trying to run a teaching tutorial on Fourier space in MRI image generation, and consistently getting the following error:
Error using openfig
Too many input arguments.
Error in k_space_tutorial (line 20)
fig = openfig(mfilename, 'reuse')
I have made sure that the folder with the code and related files is in the directory:
>> isdir('k_Space_tutorial_David_Moratal')
ans =
logical
1
and in the path:
>> path
MATLABPATH
C:\Users\Myname\Documents\MATLAB
These are the contents of the directory:
>> dir
. half_fov.m openfig.m
.. image_test.bmp rectangular_matrix.m
README.txt imatge_i_espai_k_originals.m replay_pid10644.log
add_awgnoise.m k_space_tutorial.fig replay_pid11732.log
filtre_pas_alt.m k_space_tutorial.m replay_pid13344.log
filtre_pas_baix.m modaldlg.fig
half_fourier_fe.m modaldlg.m
half_fourier_pe.m motion_artifacts.m
Results of the debugger:
openfig is a function that comes with MATLAB, and according to its documentation, the syntax used is correct.
One of the possible reasons for a function being called correctly but leading to an error is that a different function is called inadvertently. This happens when a different function with the same name shadows (hides) the original function. An M-file in the current directory, or in an earlier directory on the path, with the same name will cause this.
Typing which openfig at the MATLAB command prompt will tell you what function is called when that name is used.
In this case, there is an M-file in the current directory with the same name. Deleting this file (or renaming it) will solve the problem.

Why do I need to run a file several times in MATLAB before it stops throwing an error?

I have been trying to debug this weird bug where I run a script in matlab and it says that it cannot find some function that I have clearly defined in a folder and also obviously imported to the running script. However, after running the script a few times it suddenly accepts it knows where the location of my function is and runs. I find this really strange because that shouldn't be happening because imports are deterministic functions, so I have no idea why running it multiple times should make a difference.
To reproduce my bug you can find my code in my project's github page. Go/cd to the folder:
research/HBF_mat_lib/HBF1_multivariant_regression/om_simulations/h_add_cv
and
run:
test_debug_script
in MATLAB.
It show throw an error:
Undefined function 'learn_HBF1_SGD' for input
arguments of type 'HBF1_parameters'.
Error in get_best_trained_hbf1_model (line 37)
[ mdl_params, errors_train, errors_test ] =
train_func( X_train, y_train, mdl_params,
iterations,visualize, X_test,y_test,
eta_c,eta_t, sgd_errors);
Error in test_debug_script (line 11)
get_best_trained_hbf1_model(slurm_job_id,
task_id)
Error in run (line 96)
evalin('caller', [script ';']);
but if you try running it enough times it runs as it should.
Things I've tried to clear this bug is clear my matlab environment, restore my path to normal, at this point I have no idea what I can do because I have also printed out what path is before executing stuff and the folder seems to be in my path variable. At this point I have no idea what I can do and why after running a few times it runs, it should ALWAYS fail but it does not...
I'd venture it's because you're creating a reference to learn_HBF1_SGD in simulation_config.m before you put the function on the Matlab path via load_paths.m, which you've made dependent on the function handle's content. Given the current structure, I'd switch to declaring train_func_name explicitly, and then use str2func to create the handle after the paths have been loaded.
Subsequent runs of the file work because the execution did not stop until after the calls to addpath have been made. And since addpath "adds the specified folders to the top of the search path for the current MATLABĀ® session", the function was on the Matlab path for subsequent runs.

Matlab Will Not Add Path

I am trying to call a function from the command window, but I constantly am obstacle by the message
Undefined function 'gDiscrPdfRnd' for
input arguments of type 'double'.
So, I searched this messaged in google. According to this post here, a possible cause for this is that matlab can not find the file. I found this page which tells of how to add the path. So, I typed in the command
addpath('C:\Users\Eli\Documents\MATLAB\final project\help')
and then I typed in
which gDiscrPdfRnd
which gave me the error 'gDiscrPdfRnd' not found. How can I fix this?
EDIT: The output of cd('C:\Users\Eli\Documents\MATLAB\final project\help');dir is
. IdealGasSimulation.zip randpdf
.. gDiscrPdfRnd funct randpdf.zip
IdealGasSimulation gDiscrPdfRnd funct.zip
There is no file gDiscrPdfRnd.m in the folder, put it into the help directory or add the folder where the gDiscrPdfRnd.m is placed.

Matlab, Mex files, undefined functions

It may seem like this question has been asked already, but after several days of dealing with this problem and searching for solutions, I am coming up empty. To begin, I am using matlab2012a
So I have the mexa64 file compiled, let's call it foo.mexa64 . My computer can handle 64 bit (matlab >>computer, returns GLNXA64). I have added the folder that foo.mexa64 is in to the path using the pathtool. I did this when I opened matlab, so the changes are there. This is also not in the root/toolbox folder, it is saved in my Documents/MATLAB.../fooDirectory folder.
I can run these mex files in the command line in a different directory and everything works fine. However I cannot call them in a function, I get the "Undefined function 'foo' for input arguments of type 'double'" error.
Using the 'which foo' function returns the path:
home/.../Documents/MATLAB/.../fooDirectory/foo.mexa64
'help foo' returns
foo not found
To check, I created a dummy.m file in the fooDirectory folder. This function can be run in other functions outside of the directory with no issue.
If you need anything else, please let me know, I am completely at a loss!

MATLAB error when running the program "try.m"

After creating a MATLAB (version 2010a) file in the editor, I am getting the below mentioned error:
"MATLAB cannot run this file because \toolbox\matlab\lang\try.m shadows it in MATLAB path"
Also with this I get an option to "change folder", "add the path". Even after clicking and working around with this option I keep getting the same message.
I looked up in the matlab manual and tried to change the path. Also I checked my path variable, the place where I am storing my matlab files is already there in the path variable. Please help correcting the error. The name of my file is try.m
The code inside 'try.m' is just:
clear all;
TRY is a reserved word in MATLAB, so you shouldn't use it for your filename. Rename "try.m" to something else and you should be fine. You can do this using the "Save As" from the Editor menu and typing a different name.
Is your file in the file editor also named lang.m? Because Matlab sometimes cannot resolve scope differences between m-files in the current directory and m-files that represent built-in functions. It does not appear to be telling you that your file is not in the path; rather it seems to be saying it cannot distinguish your file from \toolbox\matlab\lang.
Can you provide more details about what your file is, such as posting the code and including the working directory name?