I have a difficulty. I can not add a library "FOTS Simulator" to the Simulink Library Browser in MATLAB.
I was reading the site "https://www.goddardconsulting.ca/simulink-creating-custom-libraries.html" but I cannot reproduce their result.
In my computer I have installed MATLAB in :
C:\Program Files\MATLAB\MATLAB Production Server\R2015a
And I created a "FOTS Simulator" folder. In this folder are several files, including "Slblocks". So this file is in:
C:\Program Files\MATLAB\MATLAB Production Server\R2015a\toolbox\FOTS Simulator
I ran slblock.m in a directory that is on the MATLAB path. However, I wrote Browser.Library = 'FOTS_2015a' (as you can see in the code below).
It should be noted that this file (FOTS_2015a) is in .slx format in :
C:\Program Files\MATLAB\MATLAB Production Server\R2015a\toolbox\FOTS Simulator
How do I make "FOTS Simulator" appear in the Library Browser?
Code:
function BlkStruct = slblocks
BlkStruct.Name = sprintf('FOTS Simulator')
Browser.IsFlat = 1;
BlkStruct.OpenFcn = 'FOTS_2015a'
Browser.Library = 'FOTS_2015a';
BlkStruct.MaskDisplay = ''
Browser.Name = 'FOTS Simulator';
% 'OFTS Simulator' is the library name that appears in the Library Browser
BlkStruct.Browser = Browser;
end
Many of the following steps are over-kill and not required, nonetheless I would suggest doing the following:
Close MATLAB
Start MATLAB
Remove your directory from the MATLAB path, saving the change so that it is permanently removed.
Close MATLAB
move or rename your slbocks.m file (so that effectively slblocks.m for your custom library doesn't exist)
Start MATLAB (do not cd into your directory)
Try to open your custom Simulink library by typing its name at the MATLAB command line. This should generate an error saying the library cannot be found. If the library can be found then go back to step 3.
Add your directory to the MATLAB path, saving the change so that it is permanently on the path.
Try to open your custom Simulink library by typing its name at the MATLAB command line. This should open your library. If it doesn't then for some reason MATLAB is not finding your library.
Close MATLAB
create slblocks.m for your custom library putting it in your directory
Start MATLAB
Start Simulink (by opening a model or creating one from scratch)
Open the Simulink Library browser
Your custom library should appear in the list of available libraries.
Related
I am using Dymola 2017 (Compiler is Visual Studio 2013/VisualC++ 2013 express Edition (12.0)).
I tried to export different MSL examples (e.g. Modelica.Electrical.Analog.Examples.CauerLowPassAnalog) as FMU (co-sim and Model exchange). I imported the FMU back in Dymola. When I try to simulate the FMU, I get always similar error messages:
Here the FMU setting:
When I create an FMU of the example: Modelica.Electrical.Analog.Examples.CauerLowPassAnalog
The following files are created:
But when I open the file "LowPass.fmu" (as .zip file), there is just one file inside:
This is the first time the I work with the 2017 version - when I created a FMU with the 2016 version, there were always all files in the FMU.
Would be great, if someone could help me.
Thank you!
I was able to reproduce your error by importing and attempting to simulate an FMU while the current working directory was set within an existing Modelica package (i.e., a directory with the package.mo file).
To fix change your working directory to a folder without a package.mo file.
For example (cd c:/Documents/Dymola) and then import and run your FMU.
Hope that helps.
Below is my C:/Documents/Dymola folder once I create the FMU...
Everything can be deleted except the .fmu file and everything still works...
The meaning of the error message is that Dymola cannot find the extracted FMU library. It could be that your FMU is not properly extracted by Dymola.
I would first check the working directory (you can know that by typing cd in the Dymola command window), if the FMU is properly extracted there.
It might also help, if you change to a working directory close to the root (for exampe create a directory C:/tmp and cd to it), so that you don't run into problem with the path length limit in Windows.
I'm using an open source code from Matlab: http://makerzone.mathworks.com/uncategorized/activity-detection-with-matlab/
for activity detection. All data that I need is in the zip file that you can download above. When I try to run the main script activityDetection.m that classificate the data it shows this error: Undefined function or variable 'activityDetection'.
maybe knows someone how to fix it :)
I downloaded zip file and then run it on my laptop. It works just fine.
You need to change your working directory to the directory where the code is (or add the directory to your MATLAB path by typing addpath('ADRESS TO DIRECTORY')).
I am running a program on Matlab and I use spmd to parallelize my code.
The same code runs on 2 different PCs. One of them runs perfectly well, but the other doesn't and the Fatal Error occurs.
If I try to run a non-parallelized program, there are no errors. I don't know if there is a problem with this specific command or if I did something wrong myself.
Could it be related to the directories in which I have saved my code files?
If so then why does the non-parallelized program run?
I'm not sure if you still have this problem, but anyway...
The problem is with the path to preferences folder. So, you need to change it.
Mostly such error occurs if you don't have write access to this folder or its located in hidden folder.
To open the current path of the prefdir type winopen(prefdir) in matlab Command window. Then copy all files from this folder into new one (for instance C:\MATLABPreferences).
Now you need to change a path of the prefdif using .bat file with the following text:
fullfile (matlabroot, 'bin', 'matlab')
set MATLAB_PREFDIR=<New preference folder location>
"<MATLAB executable location>"
Example:
fullfile (matlabroot, 'bin', 'matlab')
set MATLAB_PREFDIR=C:\MATLABPreferences
"C:\Program Files\MATLAB\R2013b\bin\matlab.exe"
Run it and enjoy parallel computing with matlab.
More detailed explanation you can find here.
I've had problems with this, and so far the internet was not really useful. After hours of Googling, this turned out to be useful. You just need to add a new variable to your environmental variables (in case you are using Windows) named MATLAB_PREFDIR with the location of the preferred directory.
For me, it is C:\Users\Balázs\AppData\Roaming\MathWorks\MATLAB\R2014a, but you can get if you type prefdir into matlab's command line.
I am running MATLAB 2013b on a CentOS machine. Right now I have startup.m set to cd me into another directory, lets call it shared, where I keep all of my code. I also have pathdef.m set to add shared and some of its subdirectories to the MATLAB path.
The problem is that once MATLAB is open and I check the path settings, ~/matlab has also been added to the top of the path list, ahead of shared. The home folder is where I keep some old versions of code, so it causes the wrong version to be run sometimes. I've double checked my pathdef and startup files, and the ~/matlab directory is definitely not listed. What could be causing MATLAB to automatically add this directory to the path, and how can I fix it?
I'm trying to compile C shared library from Matlab. My Matlab code uses a lot of the image processing functionality. So, compiling goes fine, but when I call the dll from my application, I get messages like:
"Undefined function or method 'XYZ' for input arguments of type double".
I have verified my arguments are ok -- it's not a type problem. So, I tried adding %#function XYZ to my .m file, but that didn't help anything. Then, I tried using the -a flag in my compile command:
eval(['mcc -v -N -W lib:cshared -d ' clibdir ' -T link:lib -a edge' allFiles]);
but it fails to compile with:
Depfun error: 'Unable to locate edge as a function on the MATLAB path'
I have verified the image processing files are on my computer (I can run everything from matlab with no problem) and my path points to the directory that contains them.
I've also tried copying the toolbox .m files into my working directory, but that quickly balloons into a lot of files. And, for some functions, there is no .m - just a .mex - and i haven't found a way to include a mex file into my .dll.
What am I missing?
Have you tried including the Image Processing Toolbox folder using the -a option? For example:
mcc ... -a C:\Program Files\MATLAB\R2009a\toolbox\images\images
According to the mcc documentation, all files in this folder, as well as all files in any subfolders, are added to the CTF archive, and the folder subtree is preserved in the CTF archive.
If you don't want to include every subfolder, you can load only the files in a folder using a wildcard pattern:
mcc ... -a C:\Program Files\MATLAB\R2009a\toolbox\images\images\*
This may be necessary if there is a subfolder that may have functions or scripts that could shadow ones in the parent folder. For example, there is an edge.m function in the parent folder C:\Program Files\MATLAB\R2009a\toolbox\images\images\, and there is a ja subfolder that contains Japanese language help files (on Windows), one of which is also called edge.m. You wouldn't want this subfolder to be added when compiling, so you could either:
Remove that subfolder temporarily, add the parent folder without the wildcard option (to add the other subfolders you do want), then put that folder back.
Add the parent folder with the wildcard option (to add just the files), then separately add only the subfolders you want (such as #strel and private) with an additional -a command. NOTE: I'm uncertain if adding subfolders separately will maintain the folder subtree of the parent directory in the CTF archive in the same way as option #1 would!
If you don't want to include a large list of files that may not end up being used, you could instead try using the function DEPFUN to first get a list of dependencies for your MATLAB code. Then from this list you can find the specific Image Processing Toolbox functions your code uses and include only those when compiling. Since you specifically asked, this newsgroup thread mentions how to include a .mex file:
mcc ... -a imreconstructmex.mexw32 %# For a 32-bit Windows mex file
NOTE: There is also a MathWorks bug report I came across (which you need a login to see) that mentions a problem compiling applications using some Image Processing Toolbox functions on Windows in R2009b. There is a workaround given at the above link. This bug is fixed as of R2010a.