How set mpv2 for MATLAB? - matlab

I'm trying to run these from Karl Skretting for dictionary learning in MATLAB. It is mentioned that mpv2 java package is needed to run these scripts for sparse approximation. where can I find this package and how can i install it so that MATLAB can use its method?
Thanks for your help.

You can find it here:
http://www.ux.uis.no/~karlsk/dle/mpv2-class.zip
Extract all files to folder named 'mpv2' (so folder structure is: C:\Some\Folder\mpv2)
javaaddpath('C:\Some\Folder\')
And to test for success:
exist('mpv2.SimpleMatrix') %should return 8 indicating class.

Related

.NET methods in python (conversion from matlab code) - Delsys EMGWorks

I have a script in Matlab, which accesses a DLL and allows me to utilize the methods to import and analyse data programmatically. However, I would like to convert it to python. I have looked at using pythonnet, but I cannot get it to work. Can anyone suggest a way of replicating this behaviour in python?
Ths example is specific to Delsys and their EMGWorks software.
%locate HPF DLL within EMGworks install folder
path = ['C:\Program Files (x86)\pathtoDLL\HPF.dll'];
%make HPF assembly visible to MATLAB
NET.addAssembly(path);
%locate target HPF file
curFile = 'C:\TestFiles\MyTestFile.hpf';
%construct HPF reader
myHPFreader = HPF.HPFReader(curFile);
%invoke “GetAllSampleRates” method on HPF reader object “myHPFreader”
mySampleRates = myHPFreader.GetAllSampleRates;
Thanks Tim!
I made one small change to the great example you provided!
channel_names = emg_file.GetAllChannelNames()
The emg_file change matched the variable.
The key it seems is knowing the structure of the dll so you can instantiate the class. I looked at the Matlab docs to work this out.
1. Install Python.net
pip install pythonnet
2. Import package and make package available to Python
import clr
clr.AddReference('C:\Program Files (x86)\Delsys, Inc\EMGworks\Matlab Conversion Library \HPF.dll')
3. Instantiate class object
This was initially confusing for me. But it seems that the name of the DLL will be the name of the package. In my case the .dll is HPF.dll so my package name is HPF.
from HPF import HPFReader
emg_file = HPFReader(<filename>)
4. Utilise methods from table in matlab docs to get file info and print it out
channel_names = data.GetAllChannelNames()
for channel in channel_names:
print(channel)

where to find missing tlc file generated by simulink?

please help with this problem
while i am trying to deploy a model into Arduino mega from my 2013a 32bit matlab i had this error.
( The corresponding 'Model name.tlc' file for the MATLAB S-function 'Model name' in block 'block name' must be located in the current working directory, ...)
i have looked in many websites and forums for solution but i couldn't find, maybe because i am not familiar with matlab much. but i guess the problem is with S-function. i noticed that it is easy to get tlc file if i use s-function builder. but the current model i am trying to deploy is {M-S-Function: User-definable block written using the MATLAB S-Function API...}
what shall i do?
after i used newer version of matlab and newer version of the support package i was able to generate automatically all the files including tlc file.

How do I find selfor in Octave?

I need to implement unsupervised neural network using Octave. For that, I need to use "selforgmap" function. How do I find that function in octave or what are the packages include this function?
When I use "selforgmap", I got an error like this.
selforgmap
error: 'selforgmap' undefined near line 1 column 1
help selforgmap
error: help: 'selforgmap' not found
As of now there does not appear to be any implementation of selforgmap in octave or any of it's packages. The current neural net package, nnet, can be found at Octave Forge and the Function Reference link will show you everything currently included.
The link Andy commented with above to a current reworking if the nnet package also does not currently include selforgmap, but this could obviously change. The included function files can be seen inside the inst folder.
if MATLAB's selforgmap is not an option for you, you will either need to code your own implementation or switch bto another programming language. A quick search does reveal a Python implementation of selforgmap that may serve your purpose.

Stubs in Matlab Toolbox Testing

As a follow up to my previous question, I run into a new obstacle: how to generate stubs for functions in a toolbox?
I found Andy Campbell's solution for the non toolbox case. This does not work in my case because Matlab complains: package directories are not allowed in MATLAB path in Pathfixtures!
I also don't see how this concept will overwrite the import statements within the toolbox, e.g. in file2.
This is my setup:
+folder1/file1.m
+folder1/runtestsuite.m
+folder1/unittest_data/file1_testdata.mat
+folder1/+folder2/file2.m
+folder1/+folder2/unittest_data/overloads/file1.m
...
Let's say I want to stub file1 in file2. And file2 has as a first statement: import folder1.file1.
With
methods(Access=private)
function inject_file1_stub(testCase, answer)
import matlab.unittest.fixtures.PathFixture;
testCase.applyFixture(PathFixture(fullfile(testCase.path,'overloads')));
file1('', answer);
end
end
So currently I believe this concept is not applicable in my case, so how is this done correctly with matlab?
I know one can shadow an implementation of a function in a toolbox, if one adds another path with the same toolboxname and function to the path. For this I would have to recreate a subset of the current folder setup:
So my current idea for a fixture is
create temporary folder with tempdir
use mfilename to check what subset of the toolbox directories I have to recreate
generate folder structure
copy from the overload folder to the new toolbox system
Add this to path
Run tests
In teardown
remove the temporary folder
remove the entry from path
I have not implemented this yet, and seems a bit redundant knowing that there is a Pathfixture in matlab already.
Pointers to other toolboxes which show how they have solved these kind of problems are also welcome.
It is true that you can't add subfolders of packages to the path, but that doesn't mean you can't shadow these path functions. To do this you need to separate the test related content out of your source location. For example, if your source looks like:
<source-home>/+folder1/file1.m
<source-home>/+folder1/+folder2/file2.m
Then you can put your tests somewhere else so your structure would look something like:
<test-home>/file1Test.m
<test-home>/file2Test.m % could also put tests into packages if you want
<test-home>/overloads/+folder1/file1.m
<test-home>/overloads/+folder1/+folder2/file2.m
Then inside of file1Test and/or file2Test you would use a PathFixture to add:
<test-home>/overloads/
to the path.
Also, another thing to consider is defining an interface in your source code for these dependencies and leveraging dependency injection (with or without a DI framework) in order to get test specific behavior into your tests.

Some problems about the mexLasso function

I am a student who is envolving in a research about robust visual tracking.
And these days ,I had met a problem in my study.
The teacher gave me a project of matlab code about the research, when I try to run this code, and the program error is as follows:
??? Attempt to execute SCRIPT mexLasso as a function:
F:\L1_Tracking_standard_car\mexLasso.m
Error in ==> L1Tracking_release at 95
c = mexLasso(Y(:,i), [A fixT], param);
Error in ==> demo at 46
tracking_res = L1Tracking_release( s_frames, sz_T, n_sample, init_pos,
res_path, fcdatapts);
When I go to the program tracking, I found that mexLasso function does not exist, Only get an empty mexLasso.m file and a mexLasso.mexw32 files.
My OS version is Windows 7 64bit,and the matlab is matlab 7.12.0 r2011a
Does anybody here knows the causes of my problem?
Anymore, I wonder if anybody knows who has the source code of the binary file mexLasso.mexw32.Because I thought that if I can get the source code of the file mexLasso.mexw32,then I could compile its 64 bit version myself.(I doubt that my os could not recognize the .mexw32 file.)
I hope my express clear enough to let you come to help me ,thanks a lot!
I think your analysis is basically correct - mexLasso is intended to be a MEX function, but MATLAB is finding only mexLasso.m which presumably contains help text. Unfortunately, the error you're getting isn't terribly helpful. As I see it, you have two options:
Obtain the source code for mexLasso and recompile on WIN64
Run the WIN32 version of MATLAB on your WIN64 machine
the function mexLasso comes from the SPAMS toolbox
http://www.di.ens.fr/willow/SPAMS/.
You can find the sources there and compile the mex file corresponding to your OS.
First, you need to find mexLasso.cpp file in http://spams-devel.gforge.inria.fr/downloads.html as Marial has already mentioned.
Then you can find and download the recent version of SPAMS.
A following stage is just to execute compile.m file on your MATLAB.
Finally you can find mexLasso.mexw64 in the build folder.
Good luck.