SPM12 debugging on Matlab - matlab

I have a problem using SPM on Matlab. I have an m-file that I need to debug and I have not written.
This code is old and probably the error is hopefully given by the difference in syntax of the newer versions.
The error pops out using this function spm_get_files, originally present in the code. When changing this function to spm_get (I found that these two functions are supposedly equivalent) I get the following error:
Error using spm_get (line 1726)
Illegal Action string
Error in suj6 (line 46)
Fr3 = spm_get('/home/***/folder','a3*093.img');
where '/home/***/folder','a3*093.img' is the directory of the input files I want to analyze. These are fMRI scans.
My Matlab version is 9(R2016a) and the SPM is SPM12. (The code is old and was originally written in SPM99)
Anyone can help me out?
Thank you!

spm_get_files is basically just this one line of code:
varargout = {spm_get('Files',varargin{:})};
Clearly if you would like to switch back to using spm_get, you need to explicitly add 'Files' as the first argument.

Related

Error "Function 'subsindex' is not defined for values of class 'embedded.fi'." When Changing Matlab Version

I have a struct 'ss' in Matlab that has a number of fields that are all zero'd in the beginning.
Declarations:
ss = struct;
ss.angle_spit = zeros(ais,his,tis,2);
ss.angle_neck = zeros(ais,his,tis,2);
I then go into a for loop and each iteration I update these values like such.
ss.angle_spit(ai,hi,fi,ti,1) = angle_spit_d;
ss.angle_spit(ai,hi,fi,ti,2) = angle_spit_u;
I was running this code on Matlab version R2015a with no errors, however, when I started to run it on a different computer running R2012a it gives me the error
"Error using subsindex
Function 'subsindex' is not defined for values of class 'embedded.fi'.
Error in spit_additup_11a_for12long3_fixqs (line 409)
ss.angle_spit(ai,hi,fi,ti,1) = angle_spit_d;"
My understanding is that I am trying to index the struct and that is not a possibility in 2012 and it is in 2015. Am I correct in assuming this, and if so, how would you go about changing the code to support this in 2012? Would you just create many more fields for the struct? Thank You.
I think the problem is that you are creating an index variable called fi and it's being confused with the function fi from the Fixed-Point Designer. When you try to use it as an index into the structure field ss.angle_spit, it throws the given error. The version-dependence of the error is more likely a dependence on whether the Fixed-Point Designer is included with your installation or not.
Try renaming fi to something else. I would expect that to fix the problem.
On a broader note, you should avoid giving variables the same name as an existing function, since it can either shadow that function or lead to strange behavior like you're seeing. As such, you should also rename your structure variable, since ss is already an existing function.

Matlab RMI error in function contains at startup and during runtime

In the last couple days (since changing from Matlab 2017a pre-release to Matlab R2017a) I have been getting an error message when starting up Matlab, which states that the function or variable 'isTextStrict' is undefined:
Something similar occurs when actually calling the function contains, as for example in this small code snippet:
contains('test','test')
which throws the error
Undefined function or variable 'isTextStrict'.
Error in contains (line 37)
if ~isTextStrict(s)
And similarly:
Has anyone seen this problem before? This did not occur previously.
I would appreciate your help!
I had the same problem and reinstalling (after deleting both the problematic installation of R2017a and the pre-release version) solved the problem. I think I had left an open instance of the pre-release version when installing the R2017a, so that may be the problem.

Matlab: Error in copied and renamed function [duplicate]

I using the function dtw in the latest MATLAB release, and would like to tweak a few parts of it. To get started, I typed:
edit dtw
I saved the resulting code to file called dtw_Copy.m, and changed the name of the function to dtw_Copy as well. Going through the code line by line with a set of input parameters x and y, around line 90:
[metric, varargin] = getmutexclopt({'absolute','euclidean','squared','symmkl'},'euclidean',varargin);
I receive an error message:
Undefined function 'getmutexclopt' for input arguments of type 'cell'.
I also get this error message if I do not go through the code line by line, and simply type dtw_Current(x,y), after again testing a set of input parameters x and y.
Upon running:
help 'getmutexclopt'
it is indicated that getmutexclopt is not found. I tried also:
edit 'getmutexclopt'
But am told that currentDirectory/getmutexcloptm.m does not exist.
I tried:
which getmutexclopt
And am told that getmutexclopt is not found.
Searching online, I found a resource that seemed straight-forward in trouble-shooting this error. The resource recommends to ensure the toolbox is installed. I am unsure which toolbox supports the function getmutexclopt, and so I type the function name into the website. This results in a message that: "Your search - getmutexclopt - did not match any documents."
The resource also recommends verifying the path used to access the function. I followed the instructions to do so, and when I typed:
which -all getmutexclopt
I receive:
currentDirectory\matlab\toolbox\signal\signal\private\getmutexclopt.m % Private to signal
This seems to indicate that the function is in the signal toolbox, which is private? Is there a possibility to still run dtw_Current(x,y) and/or to run its contents line by line?
Yes, this issue is because the function getmutexclopt is a private function. You'll need to make a copy of that function if you hope to safely call it from your copy of dtw. It appears to be a basic function (type edit private/getmutexclopt.m in your Command Window) so you may be able to add it as a sub-function to your dtw_Copy/dtw_Current.
See also this question – adding private functions to the search path is not allowed.

Cannot use some Matlab MPC Toolbox functions

I'm trying to use for example setoutdist Matlab function from the MPC Toolbox (I'm using Matlab R2013a on Windows 8.1). As a response I'm receiving:
Undefined function 'setoutdist' for input arguments of type 'ss'.
I am able to get help about this function using help setoutdist. When I'm typing the function name and left parenthesis I'm receiving prompt with list of the arguments. When I'm using which setoutdist -all I'm receiving proper output:
C:\Program Files\MATLAB\R2013a\toolbox\mpc\mpc\#mpc\setoutdist.m % mpc method code here
But the function doesn't work even in default Matlab path, so I don't think it is shadowed.
The same is with the other functions, for example setindist, setestim, mpc_struct, etc. but mpc, mpcstate and mpcmove functions works correctly.
I was trying: clear all, clear classess, rehash toolbox, rehash pathreset, rehash toolboxreset, restoring default paths using pathtool. I've blocked the antivirus and added exeptions to it's list. I've even reinstalled my Matlab, nothing helped.
Maybe this is significant: when I'm trying to edit the setoutdist.m I'm receiving message that access is denied.
I will extremly appreciate any help...
How are you calling setoutdist? The correct syntax is one of the three (see documentation - for R2014b):
setoutdist(MPCobj,'integrators')
setoutdist(MPCobj,'remove',channels)
setoutdist(MPCobj,'model',model)
where MPCobj is a Model Predictive Controller object, created for example with the mpc function. It looks like from the error message that you are calling the function with a state-space object, which is not allowed (I'm guessing).

Using matlab code in Octave - Bayes Net Toolbox

I am trying to run Kevin Murphy's Bayes Net Toolbox in Octave and encountering some problems. It doesn't help that I'm a novice at Bayesian networks, Matlab and Octave.
This toolbox was originally written for Matlab. There is a large test file called test_BNT.m which runs through all the functionality in the toolbox. Most of the error messages relate to the difference between & and && in Matlab and Octave. This is easy to fix. However, I've now come across a new problem and I don't know what to do about it.
For instance, the qmr1.m script creates an instance of the pearl_inf_engine class, sets some of the member member variables and passes the instance of the class to another function. Later on, the member variables are accessed again in a different script (parallel_protocol.m). But when this happens, the following message appears:
error: invalid index for class
error: evaluating argument list element number 1
It seems that from one script to another, it has forgotten that the class has any member variables and gives the invalid index message when you try to access them.
Is this a common error with an easy solution? Is something wrong with the path or working directory? Maybe someone else has already converted the BNT to octave and knows what to do?
Edit
I was able to get past this error message. The trick was to read the installation instructions (haha) and run addpath(genpathKPM(<BNT base directory)). genpathKPM.m is a script includes in BNT which adds all the required directories to the path.
After doing this, run test_BNT.m and change & to && and | to || at each line where it gives a warning. This will clear up most of the errors.
However, I'm still unable to run mpe1.m, mp2.m, mildew1.m and some others. The new error message I'm stuck on is:
error: invalid empty index list
error: called from:
error: C:\FullBNT-1.0.7\bnt\BNT\inference\static\#var_elim_inf_engine\find_mpe
.m at line 63, column 5
on this line of code:
eval(['sCPT.T(', sargs, num2str(jj), ')=0;']);
If I can get all the scripts to work, I'll post an answer here with the steps I took to do it.
Edit 2
I was able to get past the problem in the previous edit. Replace
eval(['sCPT.T(', sargs, num2str(jj), ')=0;']);
with
eval(['sCPT.T(', sargs, sprintf('%d',jj), ')=0;']);
The next problem is identical. Just replace num2str in the same way.
This file was apparently contributed by a user of BNT, and not written by the original author. Using eval kind of a hack, I think. A better fix would be to just rewrite the code so it doesn't use eval at all.
There is one more error in draw_graph.m, which was apparently also an outside contribution to the project. I just commented out the call to that function since I'm not interested in drawing graphs right now. After doing this, and continuing to fix shortcircuit operators, all of the tests in test_BNT.m will run.
Still, I won't create an answer for this until I can get draw_graph.m to run, too.
As a significant amount of time has passed, and the answer to the core problem was provided in the question, I will post it here so it will not stay listed as unanswered:
tl;dr: Change a few operators, solve the remaining bugs specified below, and everything works except the drawing of graphs.
Edit
I was able to get past this error message. The trick was to read the
installation instructions (haha) and run addpath(genpathKPM(<BNT base
directory)). genpathKPM.m is a script includes in BNT which adds
all the required directories to the path.
After doing this, run test_BNT.m and change & to && and | to
|| at each line where it gives a warning. This will clear up most of
the errors.
However, I'm still unable to run mpe1.m, mp2.m, mildew1.m and
some others. The new error message I'm stuck on is:
error: invalid empty index list
error: called from:
error: C:\FullBNT-1.0.7\bnt\BNT\inference\static\#var_elim_inf_engine\find_mpe
.m at line 63, column 5
on this line of code:
eval(['sCPT.T(', sargs, num2str(jj), ')=0;']);
If I can get all the scripts to work, I'll post an answer here with
the steps I took to do it.
Edit 2
I was able to get past the problem in the previous edit. Replace
eval(['sCPT.T(', sargs, num2str(jj), ')=0;']); with
eval(['sCPT.T(', sargs, sprintf('%d',jj), ')=0;']);
The next problem is identical. Just replace num2str in the same way.
This file was apparently contributed by a user of BNT, and not written
by the original author. Using eval kind of a hack, I think. A better
fix would be to just rewrite the code so it doesn't use eval at all.
There is one more error in draw_graph.m, which was apparently also
an outside contribution to the project. I just commented out the call
to that function since I'm not interested in drawing graphs right now.
After doing this, and continuing to fix shortcircuit operators, all of
the tests in test_BNT.m will run.