Error while using mex file in Colab with Octave - matlab

I am trying to use MATLAB in Colab. MATLAB is run in Colab through Octave. I have to use the MR8fast() filter, which in turn uses anigauss.c. I could successfully compile anigauss.c using
mkoctfile --mex -DMATLAB_MEX_FILE anigauss.c. anigauss.mex and anigauss.o files are created in the content folder in Colab. But while running the code which uses this function, its throwing an error
error: Invalid use of Script /content/anigauss.m in index expression
error: called from
MR8fast at line 20 column 13
How can I fix this error? Any help in this regard is greatly appreciated.

Related

mex function undefined error while running matlab project in octave

I am actually new to matlab.
I am trying to run this matlab project in octave on my ubuntu machine. It has a function with name 'bm3d_thr' used in one of the files (line 342 of BM3D-Net/library/bm3d-denoising/BM3D.m file) as shown below:
y_hat = bm3d_thr(z, hadper_trans_single_den, Nstep, N1, N2, lambda_thr2D,...
lambda_thr3D, tau_match*N1*N1/(255*255), (Ns-1)/2, (sigma/255), thrToIncStep, single(Tfor), single(Tinv)', inverse_hadper_trans_single_den, single(thr_mask), Wwin2D, smallLN, stepFS );
Also I have the corresponding mex file (with name 'bm3d_thr.mexa64') in my octave path.
Issue is when i try to run the project(by saying 'demo'), it gives following error:
error: 'bm3d_thr' undefined near line 342 column 9
error: called from
BM3D at line 342 column 7
bm3d_net_res at line 5 column 7
demo at line 9 column 7
Can someone please help me to figure out what is going wrong here and make it work. I guess the problem is that mex file was not compiled on my machine but authors haven't provided the source code for this mex file.
Any help would be appreciated.
Thanks in advance.
Binary MEX files from Matlab are not compatible with Octave. You need to recompile all the MEX files in your project from source using Octave's mex or mkoctfile --mex commands.
If the authors have not provided the source for this MEX file, you are SOL. Post an Issue on their GitHub repo asking for the source code. And good luck. :)

Can not build a mex file in octave using mkoctfile --mex

I am trying to build a mex file in octave. The Octave instructions says that we need to use mkoctfile --mex to build one. The file I am trying to build is in the following path:
> C:\devwork\Octave\boosted\toolbox\channels\private\rgbConvert.cpp
When I write
> mkoctfile --mex rgbConvert.cpp
I get the following error:
> g++: error: rgbConvert.cpp: No such file or directory g++: fatal
> error: no input files compilation terminated.
Note: My current directory is set correct. It is at \devwork\Octave\boosted\toolbox\channels\private
Can some one explain me why am I getting this error.
The problem is resolved using: mkoctfile --mex -DMATLAB_MEX_FILE rgbConvertMex.cpp
Hence, if you want to convert any Matlab compiled .mex file to Octave executable file, do the following two steps:
Modify wrappers.hpp file by adding #include <stdlib.h>
Save the file.
Simply run: mkoctfile --mex -DMATLAB_MEX_FILE file_name
.o file will be created.
I did it using the same and it worked fine.
Eskapp was grateful enough to release the Octave compiled MEX files. You'll need to manually add the files to the main toolbox.Please find the link here:
https://github.com/Eskapp/Piotr_vision_extrafiles_Octave
Hope it helps others :)

Invalid MEX-file error in MATLAB using GPUstart

I get following error with run GPUstart in Matlab:
Error using ==> moduleinit at 14
Invalid MEX-file 'C:\GPUmat\modules\rand\RANDModuleManager.mexw64': The
specified module could not be found.
Error in ==> GPUmatLoadModules at 18
moduleinit;
Error in ==> GPUstart at 168
GPUmatLoadModules(fullfile(GPUmatPath,'modules'));
How to solve this?
I found a similar problem in google, maybe it will help you:
http://www.mathworks.de/support/solutions/en/data/1-X8A09/index.html
Subject:
Why do I receive a "specified module could not be found" error while
running a MEX-file created from MATLAB 7.0.1 (R14SP1)? Problem
Description:
When I try to run a MEX-file I created, I receive the following error:
??? Invalid MEX-file 'MEX-file name': The specified module could not
be found. where "MEX-file name" is the name of my MEX-file. However, I
did not receive any errors when compiling the file.
Solution:
This error can occur if you do not have all of the necessary DLL files
that the MEX-function is dependent upon or if you are running a
MEX-file on a different version of MATLAB than it was compiled on.
In order to view dependent DLL files and help locate the source of
this error, you may use the third-party product "Dependency Walker".
The Dependency Walker can be downloaded from the following web site:
http://www.dependencywalker.com/
Kindly refer to the attached solutioon below for more information on
how to use the Dependency Walker to profile your MEX file.
After finding the missing dependent module, add it to the directory
where the MEX file resides or add it to the system search path.

How to properly install libsvm-3.11?

I'm using libvm-3.11. I downloaded it here and extracted. Then I set path in Matlab. After that whenever I run my program, it gives the same error always.
??? Invalid MEX-file 'E:\Gomu\Gomu General\final yr
Project\proj\libsvm-3.11\windows\svmtrain.mexw32': The specified module could not be found.
Error in ==> trysvm at 6
svmStruct = svmtrain(T,TrainMat,'showplot',true);
What should I do?
read the README file and compile the C files using mex. Mex files are platform/MATLAB version dependent. The binary download doesn't always work for everybody.

How to build levmar using MATLAB?

I am using Windows XP and matlab version is 7.10.0.
I have the levmar(Levenberg Marquardt) package from http://www.ics.forth.gr/~lourakis/levmar/levmar-2.5.tgz
In the README file, we are told to compile in matlab using mex using the following command:
mex -DHAVE_LAPACK -I.. -O -L -L levmar.c -llevmar -lclapack -lblas -lf2c.
I downloaded lapack.lib , blas.lib and f2c.lib for windows
UPDATE:
The original error got resolved after I built a vc project file given in the package.
But now there are some error messages like :
levmar.lib(misc.obj) : error LNK2019: unresolved external symbol _dgemm_ referenced in function _dlevmar_trans_mat_mat_mult
Did you create a file with a mex-function gateway? You can't just compile a c-function for Matlab; you need to do a little bit of work to take care of the I/O between Matlab and the c-code.
If you follow the steps outlined in this document, you should do fine.
You may have a look at immoptibox, which comprises Levenberg-Marquardt algorithm as well.
I just figured it out after searching a while and noticed that the levmar package included a vc project file which i needed to build and it created a file called levmar.lib .
But now I am getting some errors which involves messages like 'unable to resolve external symbols'