Two bag-of-words classifiers, Matlab - matlab

I'm trying to implement "Two bag-of-words classifiers", so I found resources at this website. http://people.csail.mit.edu/fergus/iccv2005/bagwords.html This website provides complete files including Matlab code. But I've encountered some errors while implementing the code.
I run this code on Matlab 2011b , under Windows 7.
At first, some errors occur because of path experession, but this can be soleved. At file "gg_lola_km_binary.m", replace "/" with "\" due to path expression in Windows, and it also needs to allocate appropiate path. After doing this, this error has been solved, but the next error occur:
Error using imformats>find_in_registry (line 512)
Format specifier must be a 1-D character array.
I consider whether this error results from Matlab version difference, but I don't know how to solve this problem.
Thank You

The error should be something to do with the format of your Input.Not your Matlab version. Most of the written distributed functions are constructed using basic operations and should work on most versions of Matlab (even the older versions); if not it will probably prompt an unknown function being called which it does not recognize.
Your errors seems to say that:
The function imformats>find_in_registry is looking for a 1 dimensional character array, which it did not find. (most possibly in your input file format or file path). I suggest you check again, without further information, we cannot help you.

Related

How to write a Matlab array as binary, and then read it in Fortran?

I'm extremely new to both working on Linux and Fortran, so apologies if this is a basic question.
I am trying to firstly use fwrite to save a 60x150 array that I've produced in MATLAB as a binary file, which I am then attempting to load and read in Fortran as a 60x150 array again.
In Matlab, I have used the following code to save the array. In this case the name of the array in the workspace is VP, and I'm saving it to a file also called 'VP':
>> fileID = fopen('VP','w');
>> fwrite(fileID,VP,'real*8');
>> fclose(fileID)
Next, I am copying the file over from Windows to a linux ssh server (I'm not sure if this is relevant, but thought it's worth including anything that might help).
Now, in my Fortran code, I've got:
REAL(KIND=kind(1.0D0)), DIMENSION(60,150) :: VP
...
open(unit, file="LOCATION/VP", access = "stream", form = "unformatted", iostat = stat)
if(stat /= 0) labort("Failed to open input file")
print *, wl
DO inx2=1,60
DO inx=1,150
print *,inx
READ(unit,*) VP(inx2,inx)
ENDDO
ENDDO
print *,VP(1:10,1)
Now, when I compile this there are no errors. However, when I run it, it gets to exactly the first "READ(unit,*) VP(inx2,inx)" before failing (you can tell from the print just before it).
I get the error:
forrtl: severe (257): formatted I/O to unit open for unformatted transfers, unit 111, file LOCATION/VP
Obviously I would like my actual result to be the function running and ending up with the same values in the array.
Now I've seen the question before, specifically for this error message, but that was answered by including access="stream" which I have already. Basically I am not sure at what point I am getting something wrong in this process, any help would be appreciated.
Note some things I have tried is changing the precision in fwrite, and swapping the inx2 and inx values around (but it fails on the first one so I don't believe that's the error).
Again this might be just a fundamental issue with my understanding of Fortran because I've been thrown in the deep end a bit with a project I'm working on (most of the code I'm running was produced by someone else, I'm just trying to edit a small part of it).
Edit:
Okay, thank you so much francescalus! He found the solution was to edit the line to READ(unit) VP(inx2,inx) in order to get it to run. However, the values I get by running the next line of code:
print *,VP(1:10,1)
Only the first value matches the first value in my original matlab array. Displaying VP(1:5,1:5) of the matlab array there aren't any other matching values. I might be able to figure this out on my own but as I'm already here I might as well ask as I haven't fully completed the original question (although got over a big hurdle!).
Edit 2:
Okay the next bit I've managed to figure out for myself. If anyone is searching though it was simply a case of swapping the DO loops. ie
DO inx=1,150
DO inx2=1,60
print *,inx
READ(unit,*) VP(inx2,inx)
ENDDO
ENDDO
Thanks for the help.

Residuals from ARMA estimation in MATLAB

I am trying to use the function armaxfilter from the MFE toolbox, but I get an error:
>> parameters = armaxfilter(y,1,1,1);
??? Error: File: armaxfilter.m Line: 477 Column: 21
Expression or statement is incorrect--possibly unbalanced (, {, or [.
Apparently my code is correct, as can be seen from an example from help:
EXAMPLE:
To fit a standard ARMA(1,1), use
parameters = armaxfilter(y,1,1,1)
Any idea on what is wrong?
In any case, my aim is getting residuals from an ARMA model estimation on a time series, a suggestion on an alternative way would be helpful as well.
Looking at the code (from here) , the issue is probably with the tilde output. If you are using an old version of MATLAB which does not support ~, you may get the error you mention.
There is a simple way to check this. Try out at the command line:
[~,idx] = min(1:10)
If this causes an error, you are using a version of MATLAB which does not support ~. If you want to use that particular code, you will have to either upgrade your MATLAB, or edit all the files such that examples of the tilde are replaced with some sort of dummy variable, e.g.:
[garbage,idx] = min(1:10)
As the error message describes, the problem lies in the armaxfilter.m. You should open that file and see what code is written at the specified line. I am sure you will see a bug in there.

Use of %# notation for declaring dependencies

In MATLAB, you can declare a function dependency with:
%#function myExtraFunctionName
Doing so tells MATLAB that myExtraFunctionName is required by the script or function to operate, even if it's called by an eval statement or some other method that the various dependency checkers or compilers can't figure out.
I have several files that load in .mat or other data files that are required for the script to run, and I would like to include them in a similar manner so that when I run a dependency check with, say fList = matlab.codetools.requiredFilesAndProducts, it will find these data files as well. Ultimately what I would like to be able to do is generate the list of files and pass it to zip to archive every file required to run a given script or function, including data files.
Trying to find any documentation on this feature is challenging because the MATLAB help won't let you just type in %# and searching for %#function just searches for function. Google does the same thing: "hash percent function" returns lots of information on hash tables, "%#function matlab" strips out the important characters, and "declare matlab function" "declare matlab function dependency" turns up nothing useful. I don't remember where I encountered this syntax, so I don't even know if this is a documented feature or not.
I have two questions:
Can someone point me to documentation on this syntax along with some clues as to what keywords I should be using to search?
Can this be used to declare dependencies other than m-files and, if not, how can I go about doing that?
%#function is a pragma directive that informs MATLAB Compiler that the specified function will be called indirectly using feval, eval, or the like.
This is important because the static code analyzer will not be able to detect such dependencies on its own. For instance the name of the function could be stored in a string as in:
fcn = 'myFunction';
feval(fcn)
As far as I know, this is only used by the MATLAB Compiler, nothing else.
There are other similar pragmas. For example MATLAB Coder has %#codegen compiler directive.
I don't have any answer, but maybe you can use this website:
http://www.symbolhound.com/
It let you do search using symbols.

How do I use the lteRMCDL tool?

I'm following an example from MathWorks.
When I run the code I get an erroneous output
Error in Untitled3 (line 38)
rmc = lteRMCDL(enb, ncw);
If the error you describe was preceded by:
Undefined function 'lteRMCDL' for input arguments of type 'struct'.
Then the most likely reason is that you do not have the LTE system toolbox, or that you have an older version which does not contain that function.
You can check which version of MATLAB you are running, and all the installed toolboxes you have along with their version number, by typing ver at the command line. Alternatively , you can check the location of a given function on the path by typing which lteRMCDL (this can help if the problem is that you have written a function with the same name as an existing MATLAB function, or if your MATLAB path is not set up correctly).
MATLAB online help shows by default the latest (2013b at time of writing) help and requires you to log in to show archived help files.

Mex or Compile (mcc) Matlab function that uses toolkits

Environment:
Matlab R2012a (I have access to others if necessary)
All Toolboxes/Compiler installed
Ubuntu 12.04 64bit and/or Windows 7 64bit
I am working with the source for a software package written in Matlab (unfortunately its proprietary so no code examples...sorry), and one function briefly uses the Control System Toolbox and the Signal Processing Toolbox.
I have no problem running the code on my personal computer because I have every toolbox installed, however I would like to compile (mex or mcc) JUST the function using those two toolboxes. The goal, of course, is to run the software on a machine without those toolboxes, while leaving the remaining code open to change.
According to matlab, they have no problem with you compiling code that uses almost any toolbox. Here is the list of toolboxes that support mcc compilation:
http://www.mathworks.com/products/compiler/supported/compiler_support.html
The problem arises in that mcc no longer allows compiling with the -x option to create a mex-ed version of the function, so I'm forced to create a C executable (maybe? hopefully not). This particular function takes large matrices as parameters (impractical to write as a command line argument) and returns a structure of cell arrays.
The only way around this (as I see it now) would be to write the arguments (large matrices) to the hard drive in a binary .mat file , have the compiled C binary read in the arguments, run the algorithm, and finally save the return values in another .mat for the parent thread to load back into memory.
This seems totally impractical. I would greatly appreciate alternative suggestions. Please let me know if anything here in unclear. Thanks in advance!
[Edit 1] The codegen package does not support tf.m. It seems like this should be possible (and used to be possible with the mex -x option), but I'm at a loss. Any suggestions would be greatly appreciated!
I think the reason -x is not supported anymore is the fact that Matlab now has a product called "coder", which converts .m files to .c files and can also create .mex files from "suitable" .m files using the option -args to specify the input arguments: http://www.mathworks.com/videos/generating-c-code-from-matlab-code-68964.html