s-function in simulink MATLAB - matlab

I'm getting message
Error in S-function 'project1_simu/S-Function': S-Function 'chiu_sfcn' does not exist
whenever i run my simulink file which contains s-function block diagram. Any tips to resolving this problem?

You need to compile the s function using mex.
Then the mex32 output file needs to be on the matlab path.

For an S-Function, you need to make sure your C, Matlab, or Fortran Code is where Simulink expects it to be. My guess is your code exists, but isn't in the directory simulink expects.
Right click on the S-Function Block in your Simulink Project -> Choose S-Function Parameters.
Click on the Edit button next to the S-function name.
It will probably tell you the S-Function source cannot be found. It will then prompt you to either browse for the code or open an editor.
If you can't figure out where this file is located and you have the code your best bet is to open the Editor from this dialog box.
From there just paste the code and save it as 'chiu_sfcn'. You don't need to put a file extension, or browse to a different folder. It should automatically save it in the right folder for you.

It is possible that your version of Matlab is newer
than the version of Matlab used to produce the S-function.
If this is the case, I believe that the S-function
must be recreated in a newer version of Matlab
in order to interface with newer versions of Matlab.

Related

Visual Studio Build Solution

I had Simulink model and have generated C code from MATLAB. Basically Simulink Model has many function and one S-Function with file Extension .mexw32 (hex code). The process of C-code generation is working without any error. Now that I have C-code and header files of my application, I wanted to build the solution file(.bat file) from these files with Visual Studio.
When I tried to build the files then I am getting error as shown in picture 1.
What I conclude is, there is a problem with the .mexw32 file to build. I dont have source code (c code) for these S-function .mexw32 file. I think that could be the problem while building the solution.
Do I need source code to build the solution or that doesnt matter if I have it or not? Because only the .mexw32 file is causing the problem during buiding the solution.
Yes, you'll need the source code (or an equivalent .tlc file). A .mexw32 file will only run inside MATLAB.

Simulink executable is not reading .mat files

I have a Simulink model wihich reads some data from a .mat file using a "From File" block. For ilustration's sake I created the following simple system which has the same problem I'm experiencing with my original model:
I need to generate a C code to run the model on another PC that does not have MATLAB. I generated the code and compiled it to validate it and I noticed that the executable is not reading the .mat file. No matter what signal I put on the file, the executable runs the model using the signal available at the moment of the compilation. I even erased the .mat file and the executable ran normally. Why is this happening? it is supposed that the "From File" block is there to read a .mat file, but it is not fulfilling its purpose.
NOTE: I am using MATLAB R2012b and Simulink version 8.0. I am using the Embedded Coder target (ert.tlc) for the code generation. I tried using the Rapid Simulation target (rsim.tlc) and the executable worked properly, however the execution time was higher. So I want to find a way to use the Embedded Coder target to have a lower execution time.

exe file (simulink model build method rsim) wont update input variables?

i made exe file from simulink model using rsim method. i followed this link
how to import mat file to simulink?
that means i made simulinks input to mat file called "suma", and then comppiled it, "suma" is a mat file I save my variables from GUI.
the problem is that when i change my variables in GUI, and the "suma" varibales in that mat file change, my exe file still uses the old values that i used to compile it.
here is the code
a=get(handles.abroj, 'String');
b=get(handles.bbroj, 'String');
a=str2num(a);
b=str2num(b);
save('file_path_for_suma.mat','a','b');
system('file_path_for_exe_file') %this is for starting exe file?
zbroj3=load(file_path_to_output_exe_mat_file)
You're mixing up the way that Simulink works when simulating a model, and the way a simulation works when it has been converted to an executable.
A good example of the steps you will need to take can be found here: Using RSim Target for Parameter Survey.

Mex binaries not loaded

I am trying to use this software available at http://www.cmap.polytechnique.fr/~aspremon/ZIP/COVSEL.zip. They have a function spmlcdvec defined in a matlab file spmlcdvec.m. It further calls a function BoxQP for which they have provided a binary mex file called BoxQP.mexmac. However, when I run the function spmlcdvec it says
Undefined function 'BoxQP' for input arguments of type 'double'.
What should I do? Whats going wrong?
Run mexext in your command window. If it does not return mexmac (or mexw32 which is also present in the folder) then you you won't be able to run the BoxQP function. These are simply old files - I see that they're from 2006. If you're using any form of OS X these days you'll get mexmaci64, which is not compatible. However, it looks like they have helpfully included all of the source code so you'll be able to hopefully compile the binaries for your system. For details on compiling mex code see this.
Then, as #alrikai suggests, your BoxQP function needs to be on your path. Either make sure that you call your code from the same folder or run path from the command window and check if that directory has been properly added (if you did so). See also addpath.

Double-clicking to open a file on a standalone matlab application

I have timeseries files with their own extension (.Z4R). I have compile my matlab GUI that read them.
Right now I load these files from the GUI (look for the path...). I wondering if it's possible to just double-click on the .Z4R in order to load it into my program.
Thank you.
I understand the window part.
Where I don't know it is about this command line that accept the input (Z4D) when the GUI .exe starts. How do I know the path of the double-clicked file.
Thanks
Marc
You should be able to do this via Windows file association (assuming you are running windows).
You'll need to check the command line arguments of your app and open supplied Z4R files as appropriate.
Have a look on google to see how to set-up file associations
If your compiled Matlab GUI was created using the Matlab tool guide, you should have a function
function YourProgramName_OpeningFcn(hObject, eventdata, handles, varargin)
varargin should contain the filename you double clicked on.