How do I fix bugs while executing matlab standalone applications? - matlab

Hello stackoverflow community,
I am currently trying to create a Matlab application as a standalone application. In Matlab, the program runs fine via the GUI, however, as soon as I install the application on my desktop and run it, I get the following error messages output to the command window:
Error using dicom_getFileDetails (line 14)
Unable to load file "RE.#_STR_IMG.REGISTRATION.dcm".
Error in dicominfo (line 55)
Error in Apply_Registration/ApplyRegistrationButtonPushed (line 64)
Error in appdesigner.internal.service.AppManagementService/tryCallback (line 333)
Error in matlab.apps.AppBase>#(source,event)tryCallback(appdesigner.internal.service.AppManagementService.instance(),app,callback,requiresEventData,event) (line 35)
Error using matlab.ui.control.internal.controller.ComponentController/executeUserCallback (line 335)
Error while evaluating button PrivateButtonPushedFcn.
Code:
1+2)
% Button pushed function: OpenRegistrationFileButton
function OpenRegistrationFileButtonPushed(app, event)
% Open registration file
app.File_registrationFile = uigetfile;
end
reginfo = dicominfo(app.File_registrationFile);
What is the problem when running as a standalone application?
The Matlab Runtime Compiler matches my Matlab version. Unfortunately, I lack the expertise to move forward here.
Any help will be greatly appreciated!

You are currently only outputting the file name from uigetfile (docs), so subsequent usage of that file assume it's in the same folder as the executing app. This is likely not the case, hence the error that the file can't be loaded (because it doesn't exist).
You just need to be more explicit, get the path too and refer to the full file path instead of just the name
[file,path] = uigetfile;
app.File_registrationFile = fullfile( path, file );

Related

Getting a "Missing token: ASSIGN" error when running OpenModelica script through a batch file

I am trying to run an OpenModelica script using a DOS .bat file. But facing some issues.
The batch file runmodelica.bat has
%OPENMODELICAHOME%\bin\omc testscript.mos
The file testscript.mos is
loadModel(Modelica)
getErrorString()
loadFile("HelloWorld.mo")
simulate(HelloWorld)
getErrorString()
If I run the commands in the testscript.mos file from an OM Shell by changing to that directory, everything works fine. But If I run the batch file from the DOS prompt, I get the following error
Error processing file: testscript.mos
[C:/Users/blahblah/testscript.mos:2:1-2:1:writable] Error: Missing token: ASSIGN
# Error encountered! Exiting...
# Please check the error message and the flags.
Execution failed!
The HelloWorld.mo file comes with the standard installation and I haven't modified it
class HelloWorld
Real x(start = 1);
parameter Real a = 1;
equation
der(x) = - a * x;
end HelloWorld;
I am new to OpenModelica and searched online but couldn't find a solution. Any help is appreciated.
All the commands run in the OM Shell but not when invoked from the bat file.
The script code needs to be valid Modelica, so you need ; after each command.
loadModel(Modelica);
getErrorString();
loadFile("HelloWorld.mo");
simulate(HelloWorld);
getErrorString();

Path fo file MATLAB

I began using MatLab and faced problem with setting up path.
%% Set path and file name %Set main folder
defaultFolder=fileparts(fileparts(mfilename('/Users/s2986149/Desktop/MTP/Exported_STL_files/scaphoid_lunate_sl_ligament_smooth.stl')));
pathName=fullfile(defaultFolder,'MTP','Exported_STL_files');
% File name for STL
fileName=fullfile(pathName,'scaphoid_lunate_sl_ligament_smooth.stl');
%% Import a txt type STL file as patch data
[stlStruct] = import_STL(fileName);
Error using textscan
Invalid file identifier. Use fopen to generate a valid file identifier.
Error in txtfile2cell (line 16)
T=textscan(fid,'%s','delimiter', '\n','Whitespace','');
Error in import_STL (line 16)
T=txtfile2cell(fileName);
Error in Meshing (line 17)
[stlStruct] = import_STL(fileName);
In the terminal
$ pwd
/Users/s2986149/Desktop/MTP/Exported_STL_files
Thanks in advance
NataCalc

"Undefined function or variable" loadAudioPlugin

I am trying to run this simple command on Matlab to load a VST:
hostedPlugin = loadAudioPlugin(pluginpath)
However, I am getting the following error: Undefined function or variable 'loadAudioPlugin'.
What's wrong? I can't seem to figure it out... This is the output I get when I type the "ver" command:
...
Audio System Toolbox Version 1.2 (R2017a)
...
The Audio system toolbox seems to be installed correctly. And the path is set correctly apparently, I can see the "loadAudioPlugin.p" file in the compiled folder.
Any ideas why Matlab says the loadAudioPlugin is not a function??

Matlab error for interface script

I'm using ksvdbox for my research. After installing as guided in Readme, I run ksvddemo. I throws the following error:
Attempt to execute SCRIPT sprow as a function:
C:\Users\thdo\Documents\MATLAB\ClassificationV2\ClassificationV2\ksvdbox\private_ccode\sprow.m
Error in ksvd>optimize_atom (line 515)
[gamma_j, data_indices] = sprow(Gamma, j);
Error in ksvd (line 449)
[D(:,p(j)),gamma_j,data_indices,unused_sigs,replaced_atoms] = optimize_atom(data,D,p(j),Gamma,unused_sigs,replaced_atoms);
Error in ksvddemo (line 74)
[Dksvd,g,err] = ksvd(params,'verbose');
In ksvdbox, there is a script named "sprow.m" but there is no code inside this file, only comments. In fact, there is another file named "sprow.c" in the same folder. I tried to rename "sprow.m" but it throws another error:
Underfined function or variable 'sprow'
The interesting thing is that the code works for Matlab2014a, but the errors happen on Matlab2015b.
Could you please suggest me a solution?

Matlab Distributed Server parfor can't find mex opencv files

everyone!
I'm trying to parallelize an algorithm that uses mex files from mexopencv (KNearest.m, KNearest_.mexw32).
The program is based vlfeat (vlsift.mex32) + mexopencv (KNearest.m and KNearest_.mexw32).I classify descriptors obtained from images.
All the code is located on the fileshare
\\ LAB-07 \ untitled \ DISTRIB \ (this is the program code)
\\ LAB-07 \ untitled \ + cv (mexopencv)
When I run the program with matlabpool close everything works well.
Then I make matlabpool open (2 computers on 2 cores each. ultimately 4 worker, but now I use for testing only 2 workers on the computer and run the program which)
PathDependencises from fileshare -> \LAB-07\untitled\DISTRIB\ , \LAB-07\untitled+cv
Before parfor loop I train classifier on the local machine
classifiers = cv.KNearest
classifiers.train(Descriptors',Labels','MaxK',1)
Then run parfor
descr=vlsift(img);
PredictClasses = classifiers.predict(descr');
Error
Error in ==> KNearest>KNearest.find_nearest at 173
Invalid MEX-file '\\LAB-07\untitled\+cv\private\KNearest_.mexw32':
The specified module could not be found.
That is KNearest.m finds, but no KNearest_.mexw32. Because KNearest_.mexw32 located in private folder, I changed the code KNearest.m (everywhere where it appeal KNearest_ () changed to cv.KNearest_ (). Example: this.id = сv.KNearest_ ()) and placed in a folder with KNearest_.mexw32 KNearest.m. As a result, get the same error
Immediately after matlabpool open file search on workers
pctRunOnAll which ('KNearest.m')
'KNearest.m' not found.
'KNearest.m' not found.
'KNearest.m' not found.
pctRunOnAll which ('KNearest_.mexw32')
'KNearest_.mexw32' not found.
'KNearest_.mexw32' not found.
'KNearest_.mexw32' not found.
after cd \LAB-07\untitled+cv
pctRunOnAll which ('KNearest.m')
\\LAB-07\untitled\+cv\KNearest.m
\\LAB-07\untitled\+cv\KNearest.m % cv.KNearest constructor
\\LAB-07\untitled\+cv\KNearest.m
>> pctRunOnAll which ('KNearest_.mexw32')
\\LAB-07\untitled\+cv\KNearest_.mexw32
\\LAB-07\untitled\+cv\KNearest_.mexw32
\\LAB-07\untitled\+cv\KNearest_.mexw32
I ran and FileDependecies, but the same result.
I do not know this is related or not, I display during the execution of the program classifiers
after training and before parfor
classifiers =
cv.KNearest handle
Package: cv
Properties:
id: 5
MaxK: 1
VarCount: 128
SampleCount: 9162
IsRegression: 0
Methods, Events, Superclasses
Within parfor before classifiers.predict
classifiers =
cv.KNearest handle
Package: cv
Properties:
id: 5
I tested the file cvtColor.mexw32. I left in a folder only 2 files cvtColor.mexw32 and vl_sift
parfor i=1:2
im1=imread('Copy_of_start40.png');
im_vl = im2single(rgb2gray(im1));
desc=vl_sift(im_vl);
im1 = cvtColor(im1,'RGB2GRAY');
end
The same error, and vl_sift work, cvtColor no...
If the worker machines can see the code in your shared filesystem, you should not need FileDependencies or PathDependencies at all. It looks like you're using Windows. It seems to me that the most likely problem is file permissions. MDCS workers running under a jobmanager on Windows by default run not using your own account (they run using the "LocalSystem" account I think), and so may well simply not have access to files on a shared filesystem. You could try making sure your code is world-readable.
Otherwise, you can add the files to the pool by using something like
matlabpool('addfiledependencies', {'\\LAB-07\untitled\+cv'})
Note that MATLAB interprets directories with a + in as defining "packages", not sure if this is intentional in your case.
EDIT
Ah, re-reading your original post, and your comments below - I suspect the problem is that the workers cannot see the libraries on which your MEX file depends. (That's what the "Invalid MEX-file" message is indicating). You could use http://www.dependencywalker.com/ to work out what are the dependencies of your MEX file, and make sure they're available on the workers (I think they need to be on %PATH%, or in the current directory).
Edric thanks. There was a problem in the PATH for parfor. With http://www.dependencywalker.com/ looked missing files and put them in a folder +cv. Only this method works in parfor.
But predict in parfor gives an error
PredictClasses = classifiers.predict(descr');
??? Error using ==> parallel_function at 598
Error in ==> KNearest>KNearest.find_nearest at 173
Unexpected Standard exception from MEX file.
What() is:..\..\..\src\opencv\modules\ml\src\knearest.cpp:365: error: (-2) The search
tree must be constructed first using train method
I solved this problem by calling each time within parfor train
classifiers = cv.KNearest
classifiers.train(Descriptors',Labels','MaxK',1)
But it's an ugly solution :)